public IHttpActionResult GetTicketLog(string taskId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var clientTicketLog = db.GetTicketLog(taskId).ToList(); List <ClientTicketLog> ticketLogList = new List <ClientTicketLog>(); if (clientTicketLog.Count > 0) { for (int i = 0; i < clientTicketLog.Count; i++) { ClientTicketLog ticketLog = new ClientTicketLog(); ticketLog.CreatedBy = clientTicketLog[i].AssignedBy; ticketLog.Description = clientTicketLog[i].Description; ticketLog.Status = clientTicketLog[i].Status; ticketLog.TaskDate = clientTicketLog[i].TaskDate; ticketLog.ActivityLogId = clientTicketLog[i].ActivityLogId; ticketLog.Department = clientTicketLog[i].Department; var atchmts = db.ActivityAttachments.Where(x => x.ActivityId == ticketLog.ActivityLogId).ToList(); // ticketLog.Attachments = atchmts.Select(x => x.AttachmentURL).ToArray(); List <Attachment> attachments = new List <Attachment>(); if (atchmts.Count > 0) { foreach (var at in atchmts) { Attachment att = new Attachment(); att.AttachmentUrl = at.AttachmentURL; att.FileName = at.Name; att.Id = at.Id; attachments.Add(att); } // ticketLog.Attachments= db.ActivityAttachments.Where(x => x.ActivityId == ticketLog.ActivityLogId).Select(x => new { value = x.AttachmentURL, label = x.Name }).ToList(); } ticketLog.Attachments = attachments; ticketLogList.Add(ticketLog); } } var clientId = User.Identity.GetUserId(); var lastRespondedEmp = db.GetTicketLog(taskId).Where(x => x.AssignedById != clientId).OrderByDescending(x => x.TaskDate).FirstOrDefault(); return(Content(HttpStatusCode.OK, new { ticketLogList, lastRespondedEmp })); } } 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")); } }