Esempio n. 1
0
        public ActionResult Details(TicketReplyModel ticketReplyModel, string resolved, string inprogress, string onHold, string replied)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var file     = Request.Files;
                    var statusId = 0;

                    if (!string.IsNullOrEmpty(resolved))
                    {
                        statusId = (int)StatusMain.Status.Resolved;
                    }
                    else if (!string.IsNullOrEmpty(inprogress))
                    {
                        statusId = (int)StatusMain.Status.InProgress;
                    }
                    else if (!string.IsNullOrEmpty(onHold))
                    {
                        statusId = (int)StatusMain.Status.OnHold;
                    }
                    else if (!string.IsNullOrEmpty(replied))
                    {
                        statusId = (int)StatusMain.Status.Replied;
                    }

                    ReplyAttachment        replyAttachment        = new ReplyAttachment();
                    ReplyAttachmentDetails replyAttachmentDetails = new ReplyAttachmentDetails();

                    // ReSharper disable once CollectionNeverQueried.Local
                    var listofattachments = new List <ReplyAttachment>();
                    // ReSharper disable once CollectionNeverQueried.Local
                    var listofattachmentdetails = new List <ReplyAttachmentDetails>();

                    for (int i = 0; i <= file.Count - 1; i++)
                    {
                        if (file[i] != null && file[i].ContentLength > 0)
                        {
                            string extension = Path.GetExtension(file[i].FileName);
                            replyAttachment.SystemUser     = Convert.ToInt64(_sessionHandler.UserId);
                            replyAttachment.AttachmentName = file[i].FileName;
                            replyAttachment.AttachmentType = extension;
                            replyAttachment.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);
                                    replyAttachmentDetails.AttachmentBytes = fileSize;
                                }
                            }

                            listofattachments.Add(replyAttachment);
                            listofattachmentdetails.Add(replyAttachmentDetails);
                        }
                    }


                    var userId = Convert.ToInt64(_sessionHandler.UserId);

                    var message = AppendString(ticketReplyModel.Message);
                    ticketReplyModel.Message = message;

                    _ticketsReply.ReplyTicket(ticketReplyModel, listofattachments, listofattachmentdetails, null, userId, statusId);

                    var ticket = _displayTickets.TicketsDetailsbyticketId(ticketReplyModel.TrackingId);
                    ticket.ListofPriority = _priority.GetAllPrioritySelectListItem();
                    ticket.ListofStatus   = _status.GetAllStatusWithoutOverdueandEscalationSelectListItem();
                    ticket.TicketReply    = new TicketReplyModel()
                    {
                        Message    = string.Empty,
                        TicketId   = ticket.TicketId,
                        TrackingId = ticket.TrackingId
                    };

                    var listofTicketreply = _ticketsReply.ListofHistoryTicketReplies(ticketReplyModel.TrackingId);

                    if (listofTicketreply != null)
                    {
                        ticket.ListofAttachments = _attachments.GetListAttachmentsByAttachmentId(ticketReplyModel.TicketId);
                        ticket.ViewMainModel     = new ViewTicketReplyMainModel()
                        {
                            ListofReplyAttachment = _attachments.GetListReplyAttachmentsByAttachmentId(ticketReplyModel.TicketId)
                        };
                    }
                    else
                    {
                        ticket.ListofAttachments = _attachments.GetListAttachmentsByAttachmentId(ticketReplyModel.TicketId) ??
                                                   new List <Attachments>();

                        ticket.ViewMainModel = new ViewTicketReplyMainModel()
                        {
                            ListofTicketreply     = new List <ViewTicketReplyHistoryModel>(),
                            ListofReplyAttachment = new List <ReplyAttachment>()
                        };
                    }

                    TicketHistory(ticketReplyModel, resolved, inprogress, onHold, replied);
                    TempData["TicketReplyMessage"] = CommonMessages.TicketSuccessReplyMessages;

                    return(RedirectToAction("Details", "TicketDetailsAdmin", new { trackingId = ticket.TrackingId }));
                }
                else
                {
                    var ticket = _displayTickets.TicketsDetailsbyticketId(ticketReplyModel.TrackingId);
                    ticket.ListofPriority = _priority.GetAllPrioritySelectListItem();
                    ticket.ListofStatus   = _status.GetAllStatusWithoutOverdueandEscalationSelectListItem();
                    ticket.EscalatedUser  = _userMaster.GetTicketEscalatedToUserNames(ticket.TicketId);
                    ticket.ListofCategory = _category.GetAllActiveSelectListItemCategory();

                    ticket.TicketReply = new TicketReplyModel()
                    {
                        Message    = string.Empty,
                        TicketId   = ticket.TicketId,
                        TrackingId = ticket.TrackingId
                    };
                    var listofTicketreply = _ticketsReply.ListofHistoryTicketReplies(ticketReplyModel.TrackingId);

                    if (listofTicketreply.Count > 0)
                    {
                        ticket.ListofAttachments = _attachments.GetListAttachmentsByAttachmentId(ticketReplyModel.TicketId) ??
                                                   new List <Attachments>();

                        ticket.ViewMainModel = new ViewTicketReplyMainModel()
                        {
                            ListofReplyAttachment = _attachments.GetListReplyAttachmentsByAttachmentId(ticketReplyModel.TicketId),
                            ListofTicketreply     = listofTicketreply
                        };
                    }
                    else
                    {
                        ticket.ListofAttachments = _attachments.GetListAttachmentsByAttachmentId(ticketReplyModel.TicketId) ??
                                                   new List <Attachments>();

                        ticket.ViewMainModel = new ViewTicketReplyMainModel()
                        {
                            ListofTicketreply     = new List <ViewTicketReplyHistoryModel>(),
                            ListofReplyAttachment = new List <ReplyAttachment>()
                        };
                    }

                    TempData["TicketReplyMessage"] = CommonMessages.TicketErrorReplyMessages;
                    return(View(ticket));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }