public async Task <IActionResult> GetByIdAsync(int id) { if (await _repo.GetUserByIdAsync(id) is Domain.Models.Users user) { Users resource = Mapper.MapUsers(user); return(Ok(resource)); } return(NotFound("User doesn't exist")); }
public async Task <IActionResult> GetByIdAsync(string searchType, int id) { if (searchType.ToLower() == "admin") { if (await _repo.GetAdminByIdAsync(id) is Domain.Models.Admins admin) { if (await _repo.GetTicketsByAdminAsync(id) is IEnumerable <Domain.Models.Tickets> tickets) { if (tickets.Count() == 0) { return(NotFound("Admin has no tickets")); } else { IEnumerable <Tickets> resource = tickets.Select(Mapper.MapTickets); return(Ok(resource)); } } return(NotFound("dunno wha happen")); } return(BadRequest("Incorrect Id. Admin does not exist.")); } else if (searchType.ToLower() == "store") { if (await _repo.GetStoreByIdAsync(id) is Domain.Models.Stores store) { if (await _repo.GetTicketsByStoreAsync(id) is IEnumerable <Domain.Models.Tickets> tickets) { if (tickets.Count() == 0) { return(NotFound("Store has no tickets")); } else { IEnumerable <Tickets> resource = tickets.Select(Mapper.MapTickets); return(Ok(resource)); } } return(NotFound("dunno wha happen")); } return(BadRequest("Incorrect Id. Store does not exist.")); } else if (searchType.ToLower() == "user") { if (await _repo.GetUserByIdAsync(id) is Domain.Models.Users user) { if (await _repo.GetTicketsByUserAsync(id) is IEnumerable <Domain.Models.Tickets> tickets) { if (tickets.Count() == 0) { return(NotFound("User has no tickets")); } else { IEnumerable <Tickets> resource = tickets.Select(Mapper.MapTickets); return(Ok(resource)); } } return(NotFound("dunno wha happen")); } return(BadRequest("Incorrect Id. User does not exist.")); } else if (searchType.ToLower() == "ticket") { if (await _repo.GetTicketByIdAsync(id) is Domain.Models.Tickets ticket) { Tickets resource = Mapper.MapTickets(ticket); return(Ok(resource)); } return(NotFound("Incorrect ticket id. Ticket does not exist.")); } //else if (searchType.ToLower() == "complete") //{ // IEnumerable<Domain.Models.Tickets> tickets = await _repo.GetTicketsByUserAsync(id); // if (tickets.Count() == 0) // { // return NotFound("User has no tickets"); // } // else // { // IEnumerable<Tickets> resource = tickets.Select(Mapper.MapTickets); // return Ok(resource); // } // return NotFound("dunno wha happen"); // return BadRequest("Incorrect Id. User does not exist."); //} else { return(BadRequest("Incorrect search type. Please enter 'admin', 'store', 'ticket', or 'user'.")); } }