public IHttpActionResult GetClientTickets(string clientId, int?page, int?count) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var clientTickets = db.GetClientTickets(clientId, page, count).OrderByDescending(x => x.CreatedDate).ToList(); int PriorityHigh = 0; int PriorityMedium = 0; int PriorityLow = 0; List <ClientServiceModel> clientTicketsList = new List <ClientServiceModel>(); if (clientTickets.Count > 0) { for (int i = 0; i < clientTickets.Count; i++) { ClientServiceModel ticket = new ClientServiceModel(); ticket.TicketId = clientTickets[i].TaskId; ticket.Priority = clientTickets[i].Priority; ticket.Subject = clientTickets[i].subject; ticket.Status = clientTickets[i].Status; ticket.CreatedDate = clientTickets[i].CreatedDate; var Ticket = ticket.TicketId; var LastUpdateOfTicket = db.ActivitiesLogs.Where(x => x.TaskId == Ticket).OrderByDescending(x => x.TaskDate).FirstOrDefault(); ticket.LastUpdated = LastUpdateOfTicket.TaskDate; ticket.TaskOwner = clientTickets[i].TaskOwner; if (clientTickets[i].Priority == 0) { PriorityHigh++; } else if (clientTickets[i].Priority == 1) { PriorityMedium++; } else { PriorityLow++; } ticket.TotalTickets = clientTickets.FirstOrDefault().TotalCount; clientTicketsList.Add(ticket); } } int TotalCount = PriorityHigh + PriorityMedium + PriorityLow; return(Content(HttpStatusCode.OK, new { clientTicketsList, PriorityHigh, PriorityMedium, PriorityLow, TotalCount })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }