public ActionResult TicketsAssignment(int?id, TicketsAssignmentViewModel formData)
        {
            var ticket = bugTrackerHelper.GetCurrentTicketById(id.Value);

            if (id == null || ticket == null)
            {
                return(RedirectToAction("AllTickets", "Ticket"));
            }

            if (ticket.AssignedToUserId != formData.DeveloperId)
            {
                var newDeveloper = DbContext.Users.FirstOrDefault(p => p.Id == formData.DeveloperId);
                var oldValue     = (ticket.AssignedToUserId == null) ? "not assigned" : ticket.AssignedToUser.DisplayName;

                historyHelper.CreateHistory(oldValue, newDeveloper.DisplayName, ticket.Id, "Assigned Developer");

                ticket.AssignedToUserId = formData.DeveloperId;
                var message = notificationHelper.CreateAssignmentNotification(ticket.Title, newDeveloper.DisplayName);
                notificationHelper.SendNotification(ticket, message, true);
            }

            DbContext.SaveChanges();

            return(RedirectToAction("AllTickets", "Ticket"));
        }
Beispiel #2
0
        public ActionResult Edit([Bind(Include = "Id,Title,Description,Created,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,AssignedToUserId")] Tickets tickets)
        {
            // Get old values for TicketHistory table
            var    oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == tickets.Id);
            string userId    = User.Identity.GetUserId();
            string userName  = User.Identity.GetUserName();

            histHelper.CreateHistory(oldTicket, tickets, userId, userName);

            // ForSignalR

            //SignalRNotiHub sr = new SignalRNotiHub();
            //var srUser = db.Users.Find(tickets.AssignedToUserId);
            //sr.SendNotifications(srUser.UserName,"Check Assigned Ticket Id : " + tickets.Id + ".");

            if (ModelState.IsValid)
            {
                tickets.Updated = System.DateTimeOffset.Now;

                if (tickets.AssignedToUserId != null && tickets.TicketStatusId == 4)
                {
                    tickets.TicketStatusId = 3;// Assigned
                }

                db.Tickets.Attach(tickets);
                db.Entry(tickets).Property("Updated").IsModified = true;
                db.Entry(tickets).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "FirstName", tickets.AssignedToUserId);
            ViewBag.OwnerUserId      = new SelectList(db.Users, "Id", "FirstName", tickets.OwnerUserId);
            ViewBag.ProjectId        = new SelectList(db.Projects, "Id", "ProjectName", tickets.ProjectId);
            ViewBag.TicketStatusId   = new SelectList(db.TicketStatus, "Id", "StatusName", tickets.TicketStatusId);
            ViewBag.TicketTypeId     = new SelectList(db.TicketType, "Id", "TicketName", tickets.TicketTypeId);
            return(View(tickets));
        }