Exemplo n.º 1
0
        public ActionResult AddTicket()
        {
            var model = new AddEditTicketViewModel()
            {
                TicketPriorities = Context.TicketPriority.Select(x => new SelectListItem
                {
                    Value = x.Id.ToString(),
                    Text  = x.Name
                }),


                TicketTypes = Context.TicketTypes.Select(p => new SelectListItem
                {
                    Value = p.Id.ToString(),
                    Text  = p.Name
                }),
                Projects = Context.Projects.Where(p => p.Archived == false).Select(p => new SelectListItem
                {
                    Value = p.Id.ToString(),
                    Text  = p.Name
                })
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult EditTicket(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction(nameof(TicketsController.Index)));
            }

            var ticket = Context.Tickets.FirstOrDefault(p => p.Id == id.Value);

            if (ticket == null)
            {
                return(RedirectToAction(nameof(TicketsController.Index)));
            }

            var model = new AddEditTicketViewModel();

            model.TicketPriorities = Context.TicketPriority.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            model.TicketStatuses = Context.TicketStatuses.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            model.TicketTypes = Context.TicketTypes.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });
            model.Projects = Context.Projects.Where(p => p.Archived == false).Select(p => new SelectListItem
            {
                Value = p.Id.ToString(),
                Text  = p.Name
            });


            model.Title       = ticket.Title;
            model.Description = ticket.Description;
            model.Type        = ticket.TypeId;
            model.Status      = ticket.StatusId;
            model.Priority    = ticket.PriorityId;
            model.Project     = ticket.ProjectId;


            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult AddTicket(AddEditTicketViewModel formData)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var ticket = new Ticket();

            ticket.Title       = formData.Title;
            ticket.Description = formData.Description;
            ticket.PriorityId  = formData.Priority;
            ticket.StatusId    = 1;
            ticket.TypeId      = formData.Type;
            ticket.ProjectId   = formData.Project;

            ticket.CreatedById = User.Identity.GetUserId();

            Context.Tickets.Add(ticket);
            Context.SaveChanges();

            return(RedirectToAction(nameof(TicketsController.Index)));
        }
Exemplo n.º 4
0
        public ActionResult EditTicket(int?id, AddEditTicketViewModel model)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction(nameof(TicketsController.Index)));
            }

            if (!ModelState.IsValid)
            {
                return(View());
            }

            var ticket = Context.Tickets.FirstOrDefault(p => p.Id == id.Value);

            ticket.Title       = model.Title;
            ticket.Description = model.Description;
            ticket.PriorityId  = model.Priority;
            ticket.StatusId    = model.Status;
            ticket.TypeId      = model.Type;
            ticket.ProjectId   = model.Project;


            var modifiedEntities = Context.ChangeTracker.Entries();

            foreach (var change in modifiedEntities)
            {
                var DatabaseValues = change.GetDatabaseValues();

                foreach (var prop in change.OriginalValues.PropertyNames)
                {
                    var originalValue = DatabaseValues.GetValue <object>(prop).ToString();
                    var currentValue  = change.CurrentValues[prop].ToString();

                    if (originalValue != currentValue)
                    {
                        ChangeLog log = new ChangeLog()
                        {
                            UserId       = User.Identity.GetUserId(),
                            PropertyName = prop,
                            OldValue     = originalValue,
                            NewValue     = currentValue,
                            TicketId     = ticket.Id,
                        };
                        Context.ChangeLogs.Add(log);
                    }
                }
            }
            Context.SaveChanges();

            var userId = User.Identity.GetUserId();

            if (userId != ticket.AssignedToId)
            {
                var userEmail = ticket.AssignedTo.UserName;

                EmailService emailNotification = new EmailService();
                emailNotification.Send(userEmail, "A ticket assigned to you has been updated.", "Ticket Update");
            }

            if (ticket.UserNotification != null)
            {
                var userEmails   = ticket.UserNotification.Select(p => p.UserName);
                var JoinedEmails = String.Join(", ", userEmails.ToArray());


                EmailService emailNotification = new EmailService();
                emailNotification.Send(JoinedEmails, "Ticket has been updated.", "Ticket Update");
            }


            return(RedirectToAction(nameof(TicketsController.Index)));
        }