public IActionResult SearchTicket(SearchTicketRequest request) { if (request == null) { return(BadRequest()); } return(Ok(ticketRepository.SearchTicket(request))); }
public List <ViewAllTicketDTO> SearchTicket(SearchTicketRequest request) { List <ViewAllTicketDTO> allTickets = new List <ViewAllTicketDTO>(); int secretKey = 5306; request.registerId = request.registerId - secretKey; if (!string.IsNullOrEmpty(request.title)) { var result = _db.Tickets.Where(a => a.Title.Contains(request.title) && a.registerId == request.registerId).FirstOrDefault(); if (result != null) { List <int> responderArray = new List <int>(); List <string> responderName = new List <string>(); var Result = _db.Tickets.Include("register").Where(a => a.registerId == request.registerId).ToList(); foreach (var item in Result) { responderArray.Add(item.ResponderId); } foreach (var item in responderArray) { if (item != 0) { var dbResult = _db.Registers.Where(a => a.Id == item).FirstOrDefault(); responderName.Add(dbResult.FirstName + " " + dbResult.LastName); } else { responderName.Add("Not Assigned"); } } allTickets.Add(new ViewAllTicketDTO { Id = result.Id, title = result.Title, description = result.Description, status = result.Status, responderName = "Not Assigned", created = result.Created, lastModified = result.LastModified }); return(allTickets); } } else if (!string.IsNullOrEmpty(request.description)) { var result = _db.Tickets.Where(a => a.Description.Contains(request.description) && a.registerId == request.registerId).FirstOrDefault(); if (result != null) { List <int> responderArray = new List <int>(); List <string> responderName = new List <string>(); var Result = _db.Tickets.Include("register").Where(a => a.registerId == request.registerId).ToList(); foreach (var item in Result) { responderArray.Add(item.ResponderId); } foreach (var item in responderArray) { if (item != 0) { var dbResult = _db.Registers.Where(a => a.Id == item).FirstOrDefault(); responderName.Add(dbResult.FirstName + " " + dbResult.LastName); } else { responderName.Add("Not Assigned"); } } allTickets.Add(new ViewAllTicketDTO { Id = result.Id, title = result.Title, description = result.Description, status = result.Status, responderName = "Not Assigned", created = result.Created, lastModified = result.LastModified }); return(allTickets); } } else if (request.ticketid != 0) { var result = _db.Tickets.Where(a => a.Id == request.ticketid && a.registerId == request.registerId).FirstOrDefault(); if (result != null) { List <int> responderArray = new List <int>(); List <string> responderName = new List <string>(); var Result = _db.Tickets.Include("register").Where(a => a.registerId == request.registerId).ToList(); foreach (var item in Result) { responderArray.Add(item.ResponderId); } foreach (var item in responderArray) { if (item != 0) { var dbResult = _db.Registers.Where(a => a.Id == item).FirstOrDefault(); responderName.Add(dbResult.FirstName + " " + dbResult.LastName); } else { responderName.Add("Not Assigned"); } } allTickets.Add(new ViewAllTicketDTO { Id = result.Id, title = result.Title, description = result.Description, status = result.Status, responderName = "Not Assigned", created = result.Created, lastModified = result.LastModified }); return(allTickets); } } return(allTickets); }