public ActionResult Create() { Ticket model = new Ticket(); model.Created = new DateTimeOffset(DateTime.Now); model.Updated = new DateTimeOffset(DateTime.Now); model.OwnerUser = db.Users.Single(u => u.UserName == User.Identity.Name); model.OwnerUserId = model.OwnerUser.Id; ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name"); ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "UserName"); ViewBag.OwnerUserId = new SelectList(db.Users, "Id", "UserName"); ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name"); ViewBag.TicketStatusId = new SelectList(db.TicketStatuses, "Id", "Name"); ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "Name"); return View(model); }
public TicketViewModel ViewModelFromDataModel(Ticket ticket) { var ticketView = new TicketViewModel(); ticketView.Id = ticket.Id; ticketView.Title = ticket.Title; ticketView.Description = ticket.Description; ticketView.Created = ticket.Created; ticketView.Updated = ticket.Updated; ticketView.ProjectName = db.Projects.Find(ticket.ProjectId).Name; ticketView.TicketTypeName = db.TicketTypes.Find(ticket.TicketTypeId).Name; ticketView.TicketPriorityName = db.TicketPriorities.Find(ticket.TicketPriorityId).Name; ticketView.TicketStatusName = db.TicketStatus.Find(ticket.TicketStatusId).Name; ticketView.OwnerUserName = db.Users.Find(ticket.OwnerUserId).UserName; ticketView.AssignedToUserName = db.Users.Find(ticket.AssignedToUserId).UserName; return ticketView; }
public ActionResult Create(Ticket ticket) { if (ModelState.IsValid) { db.Tickets.Add(ticket); ticket.Created = DateTimeOffset.Now; db.SaveChanges(); return RedirectToAction("Details", new { id = ticket.Id}); } ViewBag.AssignedUserId = new SelectList(db.Users, "Id", "FirstName", ticket.AssignedUserId); ViewBag.OwnerId = new SelectList(db.Users, "Id", "FirstName", ticket.OwnerId); ViewBag.PriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.PriorityId); ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", ticket.ProjectId); ViewBag.StatusId = new SelectList(db.TicketStatuses, "Id", "Name", ticket.StatusId); ViewBag.TypeId = new SelectList(db.TicketTypes, "Id", "Name", ticket.TypeId); return View(ticket); }
public ActionResult Edit(Ticket ticket) { var user = db.Users.Find(User.Identity.GetUserId()); var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id); if (ModelState.IsValid) { if (oldTicket.Body != ticket.Body) { var notification = new TicketNotification(); var history = new TicketHistory(); history.OldValue = oldTicket.Body; history.NewValue = ticket.Body; history.ChangedById = User.Identity.GetUserId(); history.TicketId = ticket.Id; db.TicketHistories.Add(history); notification.UserId = ticket.AssignedUserId; notification.TicketId = ticket.Id; notification.Content = "changed the body of the ticket!"; db.TicketNotifications.Add(notification); } if (oldTicket.Title != ticket.Title) { var notification = new TicketNotification(); var history = new TicketHistory(); history.OldValue = oldTicket.Title; history.NewValue = ticket.Title; history.ChangedById = User.Identity.GetUserId(); history.TicketId = ticket.Id; db.TicketHistories.Add(history); notification.UserId = ticket.AssignedUserId; notification.TicketId = ticket.Id; notification.Content = "changed the title of the ticket!"; db.TicketNotifications.Add(notification); } //if (oldTicket.AssignedUserId != ticket.AssignedUserId) //{ // var notification = new TicketNotification(); // var history = new TicketHistory(); // history.OldValue = oldTicket.AssignedUser.DisplayName; // history.NewValue = db.Tickets.Find(ticket.Id).AssignedUser.DisplayName; // history.ChangedById = User.Identity.GetUserId(); // history.TicketId = ticket.Id; // db.TicketHistories.Add(history); // notification.UserId = ticket.AssignedUserId; // notification.TicketId = ticket.Id; // db.TicketNotifications.Add(notification); //} if (oldTicket.PriorityId != ticket.PriorityId) { var notification = new TicketNotification(); var history = new TicketHistory(); history.OldValue = oldTicket.Priority.Name; history.NewValue = db.TicketPriorities.Find(ticket.PriorityId).Name; history.ChangedById = User.Identity.GetUserId(); history.TicketId = ticket.Id; db.TicketHistories.Add(history); notification.UserId = ticket.AssignedUserId; notification.TicketId = ticket.Id; notification.Content = "changed the priority of the ticket!"; db.TicketNotifications.Add(notification); } if (oldTicket.ProjectId != ticket.ProjectId) { var notification = new TicketNotification(); var history = new TicketHistory(); history.OldValue = oldTicket.Project.Name; history.NewValue = db.Projects.Find(ticket.ProjectId).Name; history.ChangedById = User.Identity.GetUserId(); history.TicketId = ticket.Id; db.TicketHistories.Add(history); notification.UserId = ticket.AssignedUserId; notification.TicketId = ticket.Id; notification.Content = "changed the project of the ticket!"; db.TicketNotifications.Add(notification); } if (oldTicket.StatusId != ticket.StatusId) { var notification = new TicketNotification(); var history = new TicketHistory(); history.OldValue = oldTicket.Status.Name; history.NewValue = db.TicketStatuses.Find(ticket.StatusId).Name; history.ChangedById = User.Identity.GetUserId(); history.TicketId = ticket.Id; db.TicketHistories.Add(history); notification.UserId = ticket.AssignedUserId; notification.TicketId = ticket.Id; notification.Content = "changed the status of the ticket!"; db.TicketNotifications.Add(notification); } if (oldTicket.TypeId != ticket.TypeId) { var notification = new TicketNotification(); var history = new TicketHistory(); history.OldValue = oldTicket.Type.Name; history.NewValue = db.TicketTypes.Find(ticket.TypeId).Name; history.ChangedById = User.Identity.GetUserId(); history.TicketId = ticket.Id; db.TicketHistories.Add(history); notification.UserId = ticket.AssignedUserId; notification.TicketId = ticket.Id; notification.Content = "changed the type of the ticket!"; db.TicketNotifications.Add(notification); } db.Tickets.Add(ticket); ticket.Updated = DateTimeOffset.Now; db.Entry(ticket).State = EntityState.Modified; db.SaveChanges(); } return RedirectToAction("Details", new { id = ticket.Id }); }
private List<TicketHistoryWithNotification> GetTicketHistories(Ticket oldTicket, Ticket newTicket) { var histories = new List<TicketHistoryWithNotification>(); var oldUser = db.Users.Find(oldTicket.AssignedToUserId); var newUser = db.Users.Find(newTicket.AssignedToUserId); if (oldTicket.AssignedToUserId != newTicket.AssignedToUserId) { histories.Add(new TicketHistoryWithNotification() { History = new TicketHistory() { TicketId = newTicket.Id, Property = "AssignedToUserId", PropertyDisplay = "Assigned User", OldValue = oldTicket.AssignedToUserId, OldValueDisplay = oldUser != null ? oldUser.DisplayName : "Unassigned", NewValue = newTicket.AssignedToUserId, NewValueDisplay = newUser != null ? newUser.DisplayName : "Unassigned", Changed = DateTimeOffset.Now }, Notification = newUser != null ? new IdentityMessage() { Subject = "You have been assigned to a ticket.", Destination = newUser.Email, Body = "You have been assigned to a ticket. The ticket is titled '" + newTicket.Title + "'." } : null }); } if (oldTicket.Description != newTicket.Description) { histories.Add(new TicketHistoryWithNotification() { History = new TicketHistory() { TicketId = newTicket.Id, Property = "Description", PropertyDisplay = "Description", OldValue = oldTicket.Description, OldValueDisplay = "'" + oldTicket.Description + "'", NewValue = newTicket.Description, NewValueDisplay = "'" + newTicket.Description + "'", Changed = DateTimeOffset.Now }, Notification = newUser != null ? new IdentityMessage() { Subject = "The description of your ticket, " + newTicket.Title + ", has changed.", Destination = newUser.Email, Body = "The descripton for your ticket, " + newTicket.Title + ", has changed. The new description is as follows: <br /><br /><br />" + newTicket.Description } : null }); } if (oldTicket.TicketTypeId != newTicket.TicketTypeId) { var oldDisplay = oldTicket.Type != null ? oldTicket.Type.Name : "No Type"; var newType = db.TicketTypes.Find(newTicket.TicketTypeId); var newDisplay = newType != null ? newType.Name : "No Type"; histories.Add(new TicketHistoryWithNotification() { History = new TicketHistory() { TicketId = newTicket.Id, Property = "TicketTypeId", PropertyDisplay = "Ticket Type", OldValue = oldTicket.TicketTypeId.ToString(), OldValueDisplay = oldDisplay, NewValue = newTicket.TicketTypeId.ToString(), NewValueDisplay = newDisplay, Changed = DateTimeOffset.Now }, Notification = null }); } if (oldTicket.TicketStatusId != newTicket.TicketStatusId) { var oldDisplay = oldTicket.Status != null ? oldTicket.Status.Name : "No Status"; var newStatus = db.TicketStatuses.Find(newTicket.TicketStatusId); var newDisplay = newStatus != null ? newStatus.Name : "No Status"; histories.Add(new TicketHistoryWithNotification() { History = new TicketHistory() { TicketId = newTicket.Id, Property = "TicketStatusId", PropertyDisplay = "Ticket Status", OldValue = oldTicket.TicketStatusId.ToString(), OldValueDisplay = oldDisplay, NewValue = newTicket.TicketStatusId.ToString(), NewValueDisplay = newDisplay, Changed = DateTimeOffset.Now }, Notification = null }); } return histories; }
private List<TicketHistoryWithNotification> GetTicketHistories(Ticket oldTicket, Ticket newTicket) { var histories = new List<TicketHistoryWithNotification>(); if (oldTicket.AssignedUserId != newTicket.AssignedUserId) { var newUser = db.Users.Find(newTicket.AssignedUserId); histories.Add(new TicketHistoryWithNotification() { History = new TicketHistory() { Property = "AssignedUserId", PropertyDisplay = "Assigned User", OldValue = oldTicket.AssignedUserId, OldValueDisplay = db.Users.Find(oldTicket.AssignedUserId)?.UserName, NewValue = newTicket.AssignedUserId, NewValueDisplay = newUser?.UserName }, Notification = newUser != null ? new IdentityMessage() { Subject = "You have a new Notification", Destination = newUser.Email, Body = "You have been assigned to a new ticket with Id " + newTicket.Id + "!" } : null }); } if(oldTicket.Description != newTicket.Description) histories.Add(new TicketHistoryWithNotification() { History = new TicketHistory() { Property = "Description", PropertyDisplay = "Description", OldValue = oldTicket.Description, OldValueDisplay = null, NewValue = newTicket.Description, NewValueDisplay = null }, Notification = null }); if(oldTicket.PriorityId != newTicket.PriorityId) histories.Add(new TicketHistoryWithNotification() { History = new TicketHistory() { Property = "PriorityId", PropertyDisplay = "Priority", OldValue = oldTicket.PriorityId.ToString(), OldValueDisplay = oldTicket.TicketPriority?.Name, NewValue = newTicket.PriorityId.ToString(), NewValueDisplay = db.TicketPriorities.Find(newTicket.PriorityId)?.Name }, Notification = null }); return histories; }
public void DeleteTicket(Ticket tieckt) { _appDbContext.Remove(tieckt); _appDbContext.SaveChanges(); }
public void UpdateTicket(Ticket ticket) { ticket.TicketUpdated = DateTime.Now; _appDbContext.Update(ticket); _appDbContext.SaveChanges(); }
public void CreateTicket(Ticket ticket) { ticket.TicketCreated = DateTime.Now; _appDbContext.Tickets.Add(ticket); _appDbContext.SaveChanges(); }
public void TicketModified(Ticket ticket) { db.Entry(ticket).State = EntityState.Modified; db.SaveChanges(); }
public void AddTicketToUser(Ticket ticket, string userId) { db.Users.Find(userId).TicketsOwned.Add(ticket); db.SaveChanges(); }
public void RemoveFromTicket(Ticket ticket) { db.Tickets.Remove(ticket); db.SaveChanges(); }
public void AddtoTicket(Ticket ticket) { db.Tickets.Add(ticket); }
// TicketHistoryHelper is only for Changes to Tickets Edit, not for New Tickets Created public TicketHistory FindTicketChanges(Ticket newticket) { TicketHistory tickethistory = new TicketHistory(); var myTicketChanged = false; var oldticket = db.Tickets.Find(newticket.Id); tickethistory.TicketId = newticket.Id; tickethistory.Changed = DateTime.Now; if (newticket.Title != oldticket.Title) { myTicketChanged = true; tickethistory.Property = "Title"; tickethistory.OldValue = oldticket.Title; tickethistory.NewValue = newticket.Title; } if (newticket.Description != oldticket.Description) { myTicketChanged = true; tickethistory.Property = "Description"; tickethistory.OldValue = oldticket.Description; tickethistory.NewValue = newticket.Description; } if (newticket.ProjectId != oldticket.ProjectId) { myTicketChanged = true; tickethistory.Property = "Project"; tickethistory.OldValue = oldticket.Project.Name; tickethistory.NewValue = newticket.Project.Name; //tickethistory.NewValue = newticket.ProjectId.ToString(); } if (newticket.TicketTypeId != oldticket.TicketTypeId) { myTicketChanged = true; tickethistory.Property = "Ticket Type"; tickethistory.OldValue = oldticket.TicketType.Name; //tickethistory.NewValue = newticket.TicketType.Name; //tickethistory.NewValue = newticket.TicketTypeId.ToString(); var ticketType = db.TicketTypes.Find(newticket.TicketTypeId); tickethistory.NewValue = ticketType.Name; } if (newticket.TicketPriorityId != oldticket.TicketPriorityId) { myTicketChanged = true; tickethistory.Property = "Ticket Priority"; tickethistory.OldValue = oldticket.TicketPriority.Name; //tickethistory.NewValue = newticket.TicketPriority.Name; //tickethistory.NewValue = newticket.TicketPriorityId.ToString(); var ticketPriority = db.TicketPriorities.Find(newticket.TicketPriorityId); tickethistory.NewValue = ticketPriority.Name; } if (newticket.TicketStatusId != oldticket.TicketStatusId) { myTicketChanged = true; tickethistory.Property = "Ticket Status"; tickethistory.OldValue = oldticket.TicketStatus.Name; //tickethistory.NewValue = newticket.TicketStatus.Name; //tickethistory.NewValue = newticket.TicketStatusId.ToString(); var ticketStatus = db.TicketStatuses.Find(newticket.TicketStatusId); tickethistory.NewValue = ticketStatus.Name; } if (newticket.OwnerUserId != oldticket.OwnerUserId) { myTicketChanged = true; tickethistory.Property = "Owner User"; tickethistory.OldValue = oldticket.OwnerUser.DisplayName; tickethistory.NewValue = newticket.OwnerUser.DisplayName; //tickethistory.NewValue = newticket.OwnerUserId; } if (newticket.AssignedToUserId != oldticket.AssignedToUserId) { myTicketChanged = true; tickethistory.Property = "AssignedTo User"; tickethistory.NewValue = newticket.AssignedToUser.DisplayName; if (oldticket.AssignedToUserId == null) { tickethistory.OldValue = "Unassigned-To User"; } else { tickethistory.OldValue = oldticket.AssignedToUser.DisplayName; } } if (myTicketChanged == false) { // No changes were made - Set tickethistory so tickethistory.Property = "No changes made"; tickethistory.OldValue = "None"; tickethistory.NewValue = "None"; } return(tickethistory); }
public async Task <ActionResult> Edit([Bind(Include = "Id,AuthorId,AssigneeId,Created,Updated,PriorityId,ProjectId,StatusId,TypeId,Description")] Ticket ticket) { StringBuilder sb = new StringBuilder(); var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id); if (ModelState.IsValid) { ticket.Updated = DateTimeOffset.Now; db.Entry(ticket).State = EntityState.Modified; db.SaveChanges(); var newTicket = db.Tickets.Find(ticket.Id); if (oldTicket != ticket) { sb.AppendLine("Changed on " + DateTimeOffset.Now); sb.Append("<br />"); if (oldTicket.Description != newTicket.Description) { sb.AppendLine("This ticket description changed from " + (oldTicket.Description) + " to " + (newTicket.Description)); sb.Append("<br />"); } if (oldTicket.StatusId != newTicket.StatusId) { var newStatus = db.Status.Where(s => s.Id == newTicket.StatusId).Select(n => n.Name).FirstOrDefault(); sb.AppendLine("This ticket status changed from " + (oldTicket.Status.Name) + " to " + (newStatus)); sb.Append("<br />"); } if (oldTicket.TypeId != ticket.TypeId) { var newType = db.Types.Where(s => s.Id == newTicket.TypeId).Select(n => n.Name).FirstOrDefault(); sb.AppendLine("This ticket type changed from " + (oldTicket.Type.Name) + " to " + (newType)); sb.Append("<br />"); } if (oldTicket.PriorityId != ticket.PriorityId) { var newPriority = db.Priorities.Where(s => s.Id == newTicket.PriorityId).Select(n => n.Name).FirstOrDefault(); sb.AppendLine("This ticket priority changed from " + (oldTicket.Priority.Name) + " to " + (newPriority)); sb.Append("<br />"); } if (oldTicket.Assignee != ticket.Assignee) { var newAssignee = db.Users.Where(s => s.Id == newTicket.AssigneeId).Select(n => n.DisplayName).FirstOrDefault(); sb.AppendLine("This ticket assignee changed from " + (oldTicket.Assignee.DisplayName) + " to " + (newAssignee)); sb.Append("<br />"); } } var History = new History(); History.TicketId = ticket.Id; History.Body = sb.ToString(); History.Updated = DateTimeOffset.Now; db.Entry(History).State = EntityState.Modified; db.History.Add(History); db.SaveChanges(); await UserManager.SendEmailAsync(ticket.AssigneeId, "You have a ticket needing attention!", "Please log into dashboard to see if you have a new ticket or if the ticket you are working on has been updated!"); return(RedirectToAction("Index")); } return(View(ticket)); }