public ActionResult CreateComment(int id, string body) { if (id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var ticket = db.Tickets .Where(p => p.Id == id) .FirstOrDefault(); if (ticket == null) { return(HttpNotFound()); } if (string.IsNullOrWhiteSpace(body)) { TempData["ErrorMessage"] = "Comment is required"; return(RedirectToAction("Details", new { ticket.Id })); } var comment = new Comment(); comment.UserId = User.Identity.GetUserId(); comment.TicketId = ticket.Id; comment.Created = DateTime.Now; comment.CommentDescription = body; db.Comments.Add(comment); if (comment.Ticket.AssignId != null) { EmailSendingExtensions.SendNotification(comment.Ticket, "Comment"); } db.SaveChanges(); return(RedirectToAction("Details", new { id })); }
public ActionResult UploadDocument(int id, [Bind(Include = "Id,Description,FilePath")] Attechments attechments, HttpPostedFileBase document) { if (ModelState.IsValid) { if (DocumentUploder.IsWebFriendlyImage(document)) { var fileName = Path.GetFileName(document.FileName); document.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); attechments.FilePath = "/Uploads/" + fileName; attechments.TicketId = attechments.Id; attechments.UserId = User.Identity.GetUserId(); attechments.Created = DateTime.Now; db.Attechments.Add(attechments); db.SaveChanges(); attechments = db.Attechments.Where(p => p.TicketId == attechments.TicketId).FirstOrDefault(); if (attechments.Ticket.AssignId != null) { EmailSendingExtensions.SendNotification(attechments.Ticket, "Attechment"); } } return(RedirectToAction("Details", new { id })); } return(View()); }
public ActionResult Edit([Bind(Include = "Id,Title,Description,AssignId,TicketTypeId,TicketProjectId,TicketPriorityId,TicketStatusId")] Ticket ticket) { if (ModelState.IsValid) { var dateChanged = DateTimeOffset.Now; var changes = new List <History>(); var dbTicket = db.Tickets.FirstOrDefault(p => p.Id == ticket.Id); dbTicket.Title = ticket.Title; dbTicket.Description = ticket.Description; dbTicket.AssignId = ticket.AssignId; dbTicket.Updated = dateChanged; dbTicket.TicketPriorityId = ticket.TicketPriorityId; dbTicket.TicketProjectId = ticket.TicketProjectId; dbTicket.TicketStatusId = ticket.TicketStatusId; dbTicket.TicketTypeId = ticket.TicketTypeId; var originalValues = db.Entry(dbTicket).OriginalValues; var currentValues = db.Entry(dbTicket).CurrentValues; foreach (var property in originalValues.PropertyNames) { if (property != "Updated") { var originalValue = originalValues[property]?.ToString(); var currentValue = currentValues[property]?.ToString(); if (originalValue != currentValue) { var history = new History(); history.ChangedDate = dateChanged; history.NewValue = GetValueFromKey(property, currentValue); history.OldValue = GetValueFromKey(property, originalValue); history.Property = property; history.TicketHistoryId = dbTicket.Id; history.HistoryUserId = User.Identity.GetUserId(); changes.Add(history); } } } db.Histories.AddRange(changes); db.SaveChanges(); if (ticket.AssignId != null) { EmailSendingExtensions.SendNotification(ticket, "Edit"); } return(RedirectToAction("Index")); } ViewBag.AssigneeId = new SelectList(db.Users, "Id", "Name", ticket.AssignId); ViewBag.CreatorId = new SelectList(db.Users, "Id", "Name", ticket.CreatorId); ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", ticket.TicketProjectId); ViewBag.TicketPriorityId = new SelectList(db.Prorities, "Id", "Name", ticket.TicketPriorityId); ViewBag.TicketStatusId = new SelectList(db.Statues, "Id", "Name", ticket.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.Types, "Id", "Name", ticket.TicketTypeId); return(View(ticket)); }
public ActionResult AssignDevelopers(TicketAssignViewModel model) { var ticket = db.Tickets.FirstOrDefault(p => p.Id == model.Id); ticket.AssignId = model.SelectedUser; db.SaveChanges(); // Send Notification if (ticket.AssignId != null) { EmailSendingExtensions.SendNotification(ticket, "Assign"); } return(RedirectToAction("Index")); }