public ActionResult EditTicket(TicketsUserViewModel ticketsViewModel) { try { if (ModelState.IsValid) { if (Request != null && (_attachments.AttachmentsExistbyTicketId(ticketsViewModel.TicketId) && Request.Files["fileupload_1"].ContentLength != 0 && Request.Files["fileupload_2"].ContentLength != 0 && Request.Files["fileupload_3"].ContentLength != 0)) { ModelState.AddModelError("", "Delete Pervious uploaded Attachments for Uploading New Attachments"); ticketsViewModel.HasAttachment = _attachments.CheckAttachmentsExistbyTicketId(ticketsViewModel.TrackingId); ticketsViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory(); ticketsViewModel.ListofPriority = _priority.GetAllPrioritySelectListItem(); ticketsViewModel.ListofAttachments = _attachments.GetListAttachmentsByAttachmentId(ticketsViewModel.TicketId); return(View(ticketsViewModel)); } else { var attachments = new Attachments(); var attachmentdetails = new AttachmentDetails(); // ReSharper disable once CollectionNeverQueried.Local var listofattachments = new List <Attachments>(); // ReSharper disable once CollectionNeverQueried.Local var listofattachmentdetails = new List <AttachmentDetails>(); if (Request != null && Request.Files.AllKeys.Any()) { var file = Request.Files; if (Request.Files["fileupload_1"].ContentLength != 0 || Request.Files["fileupload_2"].ContentLength != 0 || Request.Files["fileupload_3"].ContentLength != 0) { for (int i = 0; i <= file.Count - 1; i++) { if (file[i] != null && file[i].ContentLength > 0) { string fileName = Path.GetFileName(file[i].FileName); string extension = Path.GetExtension(file[i].FileName); attachments.UserId = Convert.ToInt64(_sessionHandler.UserId); attachments.AttachmentName = fileName; attachments.AttachmentType = extension; attachments.CreatedDate = DateTime.Now; var inputStream = file[i]?.InputStream; if (inputStream != null) { using (var binaryReader = new BinaryReader(inputStream)) { byte[] fileSize = binaryReader.ReadBytes(count: file[i].ContentLength); attachmentdetails.AttachmentBytes = fileSize; } } listofattachments.Add(attachments); listofattachmentdetails.Add(attachmentdetails); } } var message = AppendSignature(ticketsViewModel.Message); ticketsViewModel.Message = message; _tickets.UpdateTickets(ticketsViewModel, listofattachments, listofattachmentdetails); TicketHistoryHelper ticketHistoryHelper = new TicketHistoryHelper(); TicketHistory ticketHistory = new TicketHistory { UserId = Convert.ToInt32(_sessionHandler.UserId), Message = ticketHistoryHelper.EditTicket(), ProcessDate = DateTime.Now, TicketId = ticketsViewModel.TicketId, ActivitiesId = Convert.ToInt16(StatusMain.Activities.EditedTicket) }; _ticketHistory.TicketHistory(ticketHistory); TempData["TicketReplyMessage"] = CommonMessages.TicketUpdatedSuccessReplyMessages; } else { ticketsViewModel.Message = AppendSignature(ticketsViewModel.Message); _tickets.UpdateTickets(ticketsViewModel, null, null); TicketHistoryHelper ticketHistoryHelper = new TicketHistoryHelper(); TicketHistory ticketHistory = new TicketHistory { UserId = Convert.ToInt32(_sessionHandler.UserId), Message = ticketHistoryHelper.EditTicket(), ProcessDate = DateTime.Now, TicketId = ticketsViewModel.TicketId }; _ticketHistory.TicketHistory(ticketHistory); TempData["TicketReplyMessage"] = CommonMessages.TicketUpdatedSuccessReplyMessages; } } } } return(RedirectToAction("Details", "TicketDetailsHOD", new { trackingId = ticketsViewModel.TrackingId })); } catch (Exception) { throw; } }