public ActionResult Create()
 {
     try
     {
         TicketsUserViewModel ticketsViewModel = new TicketsUserViewModel()
         {
             ListofCategory = _category.GetAllActiveSelectListItemCategory(),
             ListofPriority = _priority.GetAllPrioritySelectListItem()
         };
         //  MockInsert();
         return(View(ticketsViewModel));
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #2
0
        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;
            }
        }
        public async Task <ActionResult> Create(TicketsUserViewModel ticketsViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var file          = Request.Files;
                    var generate      = new GenerateTicketNo();
                    var applicationNo =
                        generate.ApplicationNo(_category.GetCategoryCodeByCategoryId(ticketsViewModel.CategoryId));

                    var tickets = AutoMapper.Mapper.Map <Tickets>(ticketsViewModel);
                    tickets.TicketId       = 0;
                    tickets.CreatedDate    = DateTime.Now;
                    tickets.TrackingId     = applicationNo;
                    tickets.StatusAssigned = false;
                    tickets.UserId         = Convert.ToInt32(_sessionHandler.UserId);

                    var message       = AppendString(ticketsViewModel.Message);
                    var ticketDetails = new TicketDetails()
                    {
                        Subject         = ticketsViewModel.Subject,
                        Message         = message,
                        TicketDetailsId = 0
                    };

                    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>();

                    for (int i = 0; i <= file.Count - 1; i++)
                    {
                        if (file[i] != null && file[i].ContentLength > 0)
                        {
                            string extension = Path.GetExtension(file[i].FileName);
                            attachments.UserId         = Convert.ToInt64(_sessionHandler.UserId);
                            attachments.AttachmentName = file[i].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 ticketId = _tickets.AddTickets(Convert.ToInt64(_sessionHandler.UserId), tickets, ticketDetails, listofattachments,
                                                       listofattachmentdetails);

                    if (ticketId != -1)
                    {
                        TempData["MessageTicket"] = applicationNo + ' ' + CommonMessages.TicketSuccessMessages;

                        TicketHistoryHelper ticketHistoryHelper = new TicketHistoryHelper();
                        var ticketHistory = new TicketHistory();
                        ticketHistory.UserId       = Convert.ToInt32(_sessionHandler.UserId);
                        ticketHistory.Message      = ticketHistoryHelper.CreateMessage(tickets.PriorityId, tickets.CategoryId);
                        ticketHistory.CategoryId   = tickets.CategoryId;
                        ticketHistory.PriorityId   = tickets.PriorityId;
                        ticketHistory.StatusId     = Convert.ToInt16(StatusMain.Status.Open);
                        ticketHistory.ProcessDate  = DateTime.Now;
                        ticketHistory.TicketId     = ticketId;
                        ticketHistory.ActivitiesId = Convert.ToInt16(StatusMain.Activities.Created);
                        _ticketHistory.TicketHistory(ticketHistory);

                        SendingEmailhelper sendingEmailhelper = new SendingEmailhelper();
                        Task task1 = sendingEmailhelper.SendEmailasync(applicationNo);
                        await Task.WhenAll(task1);
                    }
                    else
                    {
                        TempData["ErrorMessageTicket"] = CommonMessages.TicketErrorMessages;
                    }

                    return(RedirectToAction("Create", "Ticket"));
                }
                else
                {
                    ticketsViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory();
                    ticketsViewModel.ListofPriority = _priority.GetAllPrioritySelectListItem();
                    return(View(ticketsViewModel));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }