0% found this document useful (0 votes)
7 views2 pages

ASP.NET Core Ticket Scanning API

Uploaded by

Mina Halim
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

ASP.NET Core Ticket Scanning API

Uploaded by

Mina Halim
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using [Link].

Mvc;
using [Link];
using ProjectCore;
using ProjectDB;
using [Link];
using [Link];

namespace [Link]
{
[Route("api/[controller]")]
[ApiController]
public class ScanController : ControllerBase
{
private readonly IBaseRepository<Tkt> _TktRepository;

public ScanController(IBaseRepository<Tkt> TktRepository)


{
_TktRepository = TktRepository;
}

//[HttpGet("Scanx/{TktNoumber}")]
//public async Task<IActionResult> Scanx(string TktNoumber)
//{
// var items = await _TktRepository.Scan(TktNoumber);
// return Ok(items);
//}

/// <summary>
/// takes the ticket number then scan it if its valid it will return the
details of it
/// </summary>
/// <param name="TktNumber"> takes the number of ticket</param>
/// <returns></returns>
///

[HttpGet("ScanTicket/{TktNumber}")]
public async Task<IActionResult> ScanTicket(string TktNumber)
{
var ticket = await _TktRepository.Scan(TktNumber);
if (ticket == null)
{
return NotFound("Ticket not found");
}
if ([Link] != TktNumber)
{
return NotFound("Ticket not found");
}
return Ok(ticket); // Return the full ticket if it exists and meets the
conditions
}

/// <summary>
/// takes the ticket number and user who redeemed the ticket then scan it
if its valid and redeems the ticket
/// </summary>
/// <param name="TktNumber">takes the number of ticket</param>
/// <param name="redeemTicketRequest">takes the person who redeemed
it</param>
/// <returns></returns>
/// <summary>
///

[HttpPost("RedeemTicket/{TktNumber}")]
public async Task<IActionResult> RedeemTicket(string TktNumber, [FromBody]
RedeemTicketRequest redeemTicketRequest)
{
try
{
await _TktRepository.RedeemTicketAsync(TktNumber,
[Link]);
return Ok("Ticket redeemed successfully");
}
catch (InvalidOperationException ex)
{
return NotFound([Link]);
}
catch (Exception ex)
{
return StatusCode(500, "An error occurred while redeeming the
ticket");
}
}

}
public class RedeemTicketRequest
{
public string UserId { get; set; }
}
}

You might also like