Exemplo n.º 1
0
        public ActionResult DeleteReplyAttachment(RequestAttachments requestAttachments)
        {
            try
            {
                var result = _attachments.DeleteReplyAttachmentByAttachmentIdAgent(requestAttachments.AttachmentsId);
                if (result > 0)
                {
                    TicketHistoryHelper ticketHistoryHelper = new TicketHistoryHelper();
                    TicketHistory       ticketHistory       = new TicketHistory
                    {
                        UserId       = Convert.ToInt32(_sessionHandler.UserId),
                        Message      = ticketHistoryHelper.DeleteTicketReplyAttachment(),
                        ProcessDate  = DateTime.Now,
                        TicketId     = requestAttachments.TicketId,
                        ActivitiesId = Convert.ToInt16(StatusMain.Activities.DeleteReplyAttachment)
                    };
                    _ticketHistory.TicketHistory(ticketHistory);

                    return(Json(true, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(false, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
 public JsonResult ChangeCategory(ChangeCategoryRequestModel changeStatusRequestModel)
 {
     try
     {
         var result = _tickets.ChangeTicketCategory(changeStatusRequestModel);
         if (result)
         {
             TicketHistoryHelper ticketHistoryHelper = new TicketHistoryHelper();
             TicketHistory       ticketHistory       = new TicketHistory
             {
                 UserId       = Convert.ToInt32(_sessionHandler.UserId),
                 Message      = ticketHistoryHelper.CategoryMessage(changeStatusRequestModel.CategoryId),
                 ProcessDate  = DateTime.Now,
                 TicketId     = changeStatusRequestModel.TicketId,
                 CategoryId   = changeStatusRequestModel.CategoryId,
                 ActivitiesId = Convert.ToInt16(StatusMain.Activities.CategoryChanged)
             };
             _ticketHistory.TicketHistory(ticketHistory);
             return(Json(true, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(false, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 3
0
        public ActionResult Delete(RequestTicketReplyDeleteViewModel model)
        {
            try
            {
                if (model.TicketId != null && model.TicketReplyId != null)
                {
                    var result = _ticketsReply.DeleteTicketReply(model.TicketReplyId, model.TicketId, Convert.ToInt32(_sessionHandler.UserId));

                    if (result > 0)
                    {
                        TicketHistoryHelper ticketHistoryHelper = new TicketHistoryHelper();
                        var ticketHistory = new TicketHistory();
                        ticketHistory.UserId        = Convert.ToInt32(_sessionHandler.UserId);
                        ticketHistory.Message       = ticketHistoryHelper.DeleteTicketReplyMessage();
                        ticketHistory.ProcessDate   = DateTime.Now;
                        ticketHistory.TicketId      = model.TicketId;
                        ticketHistory.TicketReplyId = model.TicketReplyId;
                        ticketHistory.ActivitiesId  = Convert.ToInt16(StatusMain.Activities.DeleteTicketReply);
                        _ticketHistory.TicketHistory(ticketHistory);
                    }

                    return(Json(true, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(false, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 4
0
        public JsonResult DeleteTicket(string ticketid)
        {
            try
            {
                if (!string.IsNullOrEmpty(ticketid))
                {
                    var result = _iTickets.DeleteTicket(Convert.ToInt64(_sessionHandler.UserId), Convert.ToInt64(ticketid), Convert.ToInt16(StatusMain.Status.Deleted));

                    if (result > 0)
                    {
                        TicketHistoryHelper ticketHistoryHelper = new TicketHistoryHelper();
                        TicketHistory       ticketHistory       = new TicketHistory
                        {
                            UserId       = Convert.ToInt32(_sessionHandler.UserId),
                            Message      = ticketHistoryHelper.TicketDelete(),
                            ProcessDate  = DateTime.Now,
                            TicketId     = Convert.ToInt64(ticketid),
                            ActivitiesId = Convert.ToInt16(StatusMain.Activities.DeleteTicket)
                        };
                        _ticketHistory.TicketHistory(ticketHistory);
                    }
                    return(Json(new { Result = "OK" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { Result = "ERROR", Message = string.Empty }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Exemplo n.º 5
0
        public void TicketHistory(TicketReplyModel ticketReplyModel, string replied)
        {
            try
            {
                string message = string.Empty;

                TicketHistoryHelper ticketHistoryHelper = new TicketHistoryHelper();
                var ticketHistory = new TicketHistory();
                if (!string.IsNullOrEmpty(replied))
                {
                    message = ticketHistoryHelper.ReplyMessage(Convert.ToInt16(StatusMain.Status.Replied));
                    ticketHistory.StatusId = Convert.ToInt16(StatusMain.Status.Replied);
                }

                TempData["TicketReplyMessage"] = CommonMessages.TicketSuccessReplyMessages;

                ticketHistory.UserId       = Convert.ToInt32(_sessionHandler.UserId);
                ticketHistory.Message      = message;
                ticketHistory.ProcessDate  = DateTime.Now;
                ticketHistory.TicketId     = ticketReplyModel.TicketId;
                ticketHistory.ActivitiesId = Convert.ToInt16(StatusMain.Activities.Replied);
                _ticketHistory.TicketHistory(ticketHistory);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 6
0
 public JsonResult RestoreTickets(string[] ticketlist)
 {
     try
     {
         if (ticketlist.Length != 0)
         {
             foreach (var ticketid in ticketlist)
             {
                 var result = _iTickets.RestoreTicket(Convert.ToInt64(_sessionHandler.UserId), Convert.ToInt64(ticketid));
                 TicketHistoryHelper ticketHistoryHelper = new TicketHistoryHelper();
                 TicketHistory       ticketHistory       = new TicketHistory
                 {
                     UserId       = Convert.ToInt32(_sessionHandler.UserId),
                     Message      = ticketHistoryHelper.TicketRestore(),
                     ProcessDate  = DateTime.Now,
                     TicketId     = Convert.ToInt64(ticketid),
                     ActivitiesId = Convert.ToInt16(StatusMain.Activities.Restored)
                 };
                 _ticketHistory.TicketHistory(ticketHistory);
             }
             return(Json(new { status = "Success" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { status = "Fail" }));
         }
     }
     catch (Exception)
     {
         return(Json(new { status = "Fail" }));
     }
 }
        // GET: TicketHistories/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketHistory ticketHistory = TicketHistoryHelper.GetTicketHistory(id);

            if (ticketHistory == null)
            {
                return(HttpNotFound());
            }
            return(View(ticketHistory));
        }
        // GET: TicketHistories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketHistory ticketHistory = TicketHistoryHelper.GetTicketHistory(id);

            if (ticketHistory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.TicketId = new SelectList(TicketHelper.GetTickets(), "Id", "Title", ticketHistory.TicketId);
            ViewBag.UserId   = new SelectList(UserHelper.GetAllUsers(), "Id", "Email", ticketHistory.UserId);
            return(View(ticketHistory));
        }
 public ActionResult Edit([Bind(Include = "Id,TicketId,Property,OldValue,NewValue,Changed,UserId")] TicketHistory ticketHistory)
 {
     if (ModelState.IsValid)
     {
         TicketHistoryHelper.Edit(ticketHistory.Id,
                                  ticketHistory.TicketId,
                                  ticketHistory.Property,
                                  ticketHistory.OldValue,
                                  ticketHistory.NewValue,
                                  ticketHistory.Changed,
                                  ticketHistory.UserId);
         return(RedirectToAction("Index"));
     }
     ViewBag.TicketId = new SelectList(TicketHelper.GetTickets(), "Id", "Title", ticketHistory.TicketId);
     ViewBag.UserId   = new SelectList(UserHelper.GetAllUsers(), "Id", "Email", ticketHistory.UserId);
     return(View(ticketHistory));
 }
Exemplo n.º 10
0
        public ActionResult Create(TicketsViewModel ticketsViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (ticketsViewModel.HiddenUserId == null)
                    {
                        ticketsViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory();
                        ticketsViewModel.ListofPriority = _priority.GetAllPrioritySelectListItem();
                        ticketsViewModel.Message        = string.Empty;
                        ModelState.Remove("Message");
                        TempData["ErrorMessageTicket"] = "Name is AutoComplete field Don't Enter Name Choose.";
                        return(View(ticketsViewModel));
                    }

                    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.InternalUserId = Convert.ToInt64(_sessionHandler.UserId);

                    var message       = AppendSignature(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(ticketsViewModel.HiddenUserId, 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);
                    }
                    else
                    {
                        TempData["ErrorMessageTicket"] = CommonMessages.TicketErrorMessages;
                    }

                    return(RedirectToAction("Create", "TicketHOD"));
                }
                else
                {
                    ticketsViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory();
                    ticketsViewModel.ListofPriority = _priority.GetAllPrioritySelectListItem();
                    return(View(ticketsViewModel));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 11
0
        public ActionResult EditReply(TicketReplyViewModel ticketReplyViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int result;
                    var decodemessage = DecodeHtml(ticketReplyViewModel.Message);
                    ticketReplyViewModel.Message = decodemessage;

                    var                    file                   = Request.Files;
                    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>();

                    if (file.Count > 0)
                    {
                        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 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);
                                }
                            }

                            result = _tickets.UpdateTicketReply(ticketReplyViewModel, listofattachments,
                                                                listofattachmentdetails, null, Convert.ToInt32(_sessionHandler.UserId));
                        }

                        else
                        {
                            result = _tickets.UpdateTicketReply(ticketReplyViewModel, null, null,
                                                                null, Convert.ToInt32(_sessionHandler.UserId));
                        }
                    }
                    else
                    {
                        result = _tickets.UpdateTicketReply(ticketReplyViewModel, null, null,
                                                            null, Convert.ToInt32(_sessionHandler.UserId));
                    }

                    TicketHistoryHelper ticketHistoryHelper = new TicketHistoryHelper();
                    TicketHistory       ticketHistory       = new TicketHistory
                    {
                        UserId       = Convert.ToInt32(_sessionHandler.UserId),
                        Message      = ticketHistoryHelper.EditReplyTicket(),
                        ProcessDate  = DateTime.Now,
                        TicketId     = ticketReplyViewModel.TicketId,
                        ActivitiesId = Convert.ToInt16(StatusMain.Activities.EditedTicketReply)
                    };
                    _ticketHistory.TicketHistory(ticketHistory);

                    if (result > 0)
                    {
                        TempData["TicketReplyMessage"] = CommonMessages.TicketUpdatedSuccessReplyMessages;
                    }
                    return(RedirectToAction("Details", "TicketDetailsHOD", new { trackingId = ticketReplyViewModel.TrackingId }));
                }
                else
                {
                    var ticketsViewModel = _tickets.EditTicketsByTicketReplyId(ticketReplyViewModel.TrackingId, ticketReplyViewModel.TicketReplyId);
                    return(View(ticketsViewModel));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 12
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;
            }
        }
 // GET: TicketHistories
 public ActionResult Index(int ticketId)
 {
     return(View(TicketHistoryHelper.GetTicketHistorys(ticketId)));
 }
 public ActionResult DeleteConfirmed(int id)
 {
     TicketHistoryHelper.Delete(id);
     return(RedirectToAction("Index"));
 }
Exemplo n.º 15
0
        public ActionResult Edit([Bind(Include = "Id,Title,Description,Created,Updated,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,AssignToUserId")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                var user = db.Users.Find(User.Identity.GetUserId());
                TicketHistoryHelper tickethelper = new TicketHistoryHelper();
                ticket.Updated         = DateTimeOffset.UtcNow;
                db.Entry(ticket).State = EntityState.Modified;
                TicketHistory      tickethistory = new TicketHistory();
                NotificationHelper notifyHelper  = new NotificationHelper();
                var oldTicket = db.Tickets.AsNoTracking().First(t => t.Id == ticket.Id);
                if (oldTicket.AssignToUserId != null)

                {
                    if (oldTicket.AssignToUserId != ticket.AssignToUserId)
                    {
                        tickethelper.TktAssignUserHistory(ticket, user.Id);
                        notifyHelper.Notify(ticket.AssignToUserId, "BugTracker App Notification", "Your ticket needs attention. "
                                            + ticket.Title, true);
                    }
                }
                if (oldTicket.Title != ticket.Title)
                {
                    tickethelper.TktTitleHistory(ticket, user.Id);
                    notifyHelper.Notify(ticket.AssignToUserId, "BugTracker App Notification", "Your ticket needs attention. "
                                        + ticket.Title, true);
                }
                if (oldTicket.Description != ticket.Description)
                {
                    tickethelper.TktDescriptionHistory(ticket, user.Id);
                    notifyHelper.Notify(ticket.AssignToUserId, "BugTracker App Notification", "Your ticket needs attention. "
                                        + ticket.Title, true);
                }
                if (oldTicket.TicketTypeId != ticket.TicketTypeId)
                {
                    tickethelper.TktTypeIdHistory(ticket, user.Id);
                    notifyHelper.Notify(ticket.AssignToUserId, "BugTracker App Notification", "Your ticket needs attention. "
                                        + ticket.Title, true);
                }
                if (oldTicket.TicketStatusId != ticket.TicketStatusId)
                {
                    tickethelper.TktStatusIdHistory(ticket, user.Id);
                    notifyHelper.Notify(ticket.AssignToUserId, "BugTracker App Notification", "Your ticket needs attention. "
                                        + ticket.Title, true);
                }
                if (oldTicket.TicketPriorityId != ticket.TicketPriorityId)
                {
                    tickethelper.TktPriorityIdHistory(ticket, user.Id);
                    notifyHelper.Notify(ticket.AssignToUserId, "BugTracker App Notification", "Your ticket needs attention. "
                                        + ticket.Title, true);
                }

                db.SaveChanges();

                ViewBag.AssignToUserId   = new SelectList(db.Users, "Id", "FirstName", ticket.AssignToUserId);
                ViewBag.OwnerUserId      = new SelectList(db.Users, "Id", "FirstName", ticket.OwnerUserId);
                ViewBag.ProjectId        = new SelectList(db.Projects, "Id", "Title", ticket.ProjectId);
                ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.TicketPriorityId);
                ViewBag.TicketStatusId   = new SelectList(db.TicketStatus, "Id", "Name", ticket.TicketStatusId);
                ViewBag.TicketTypeId     = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId);

                return(RedirectToAction("Details", "Tickets", new { id = ticket.Id }));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 16
0
        public ActionResult Edit([Bind(Include = "Id,Title,Created,Updated,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,AssignedToUserId")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                var ticketHelper = new TicketHistoryHelper();
                var oldTicket    = ticketHelper.GetTicketById(ticket.Id);

                // Assigned to user ticket history
                if (ticket.AssignedToUserId != oldTicket.AssignedToUserId)
                {
                    var ticketHistory   = new TicketHistory();
                    var NewAssignedUser = db.Users.FirstOrDefault(u => u.Id == ticket.AssignedToUserId).FirstName;
                    ticketHistory.Changed  = DateTime.Now;
                    ticketHistory.NewValue = NewAssignedUser;
                    ticketHistory.Property = "Assigned to";
                    ticketHistory.TicketId = ticket.Id;
                    ticketHistory.UserId   = User.Identity.GetUserId();
                    db.TicketHistories.Add(ticketHistory);
                    db.SaveChanges();
                }
                var ticketNotification = new TicketNotification();
                //var user = db.Roles.FirstOrDefault(r => r.Name == "Developer");
                if (ticket.TicketStatusId == db.Ticketstatuses.FirstOrDefault(x => x.Name == "Assigned").Id)
                {
                    ticketNotification.UserId   = ticket.AssignedToUserId;
                    ticketNotification.TicketId = ticket.Id;
                    db.TicketNotifications.Add(ticketNotification);
                    db.SaveChanges();
                }
                // ticket type in ticket history
                if (ticket.TicketTypeId != oldTicket.TicketTypeId)
                {
                    var ticketHistory = new TicketHistory();
                    ticketHistory.Changed  = DateTime.Now;
                    ticketHistory.NewValue = db.TicketTypes.Find(ticket.TicketTypeId).Name;
                    ticketHistory.Property = "Ticket Category";
                    ticketHistory.TicketId = ticket.Id;
                    ticketHistory.UserId   = User.Identity.GetUserId();
                    db.TicketHistories.Add(ticketHistory);
                    db.SaveChanges();
                }
                // ticket priority in ticket history
                if (ticket.TicketPriorityId != oldTicket.TicketPriorityId)
                {
                    var ticketHistory = new TicketHistory();
                    ticketHistory.Changed  = DateTime.Now;
                    ticketHistory.NewValue = db.Ticketpriorities.Find(ticket.TicketPriorityId).Name;
                    ticketHistory.Property = "Ticket Priority";
                    ticketHistory.TicketId = ticket.Id;
                    ticketHistory.UserId   = User.Identity.GetUserId();
                    db.TicketHistories.Add(ticketHistory);
                    db.SaveChanges();
                }

                // ticket status in ticket history
                if (ticket.TicketStatusId != oldTicket.TicketStatusId)
                {
                    var ticketHistory = new TicketHistory();
                    ticketHistory.Changed  = DateTime.Now;
                    ticketHistory.NewValue = db.Ticketstatuses.Find(ticket.TicketStatusId).Name;
                    ticketHistory.Property = "Ticket Status";
                    ticketHistory.TicketId = ticket.Id;
                    ticketHistory.UserId   = User.Identity.GetUserId();
                    db.TicketHistories.Add(ticketHistory);
                    db.SaveChanges();
                }

                ticket.Updated = DateTime.Now;
                db.Tickets.Attach(ticket);
                db.Entry(ticket).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "FirstName", ticket.AssignedToUserId);
            ViewBag.OwnerUserId      = new SelectList(db.Users, "Id", "FirstName", ticket.OwnerUserId);
            ViewBag.ProjectId        = new SelectList(db.Projects, "Id", "Name", ticket.ProjectId);
            ViewBag.TicketPriorityId = new SelectList(db.Ticketpriorities, "Id", "Name", ticket.TicketPriorityId);
            ViewBag.TicketStatusId   = new SelectList(db.Ticketstatuses, "Id", "Name", ticket.TicketStatusId);
            ViewBag.TicketTypeId     = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId);
            return(View(ticket));
        }