public async Task <ActionResult> Create(int TicketId, string AttachDescription, HttpPostedFileBase image) { if (ModelState.IsValid) { var ticketAttachment = new TicketAttachment { Created = DateTime.Now, TicketId = TicketId, UserId = User.Identity.GetUserId(), Description = AttachDescription }; var ticket = db.Tickets.Find(TicketId); if (AssetHelper.IsWebFriendlyImage(image)) { var filename = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), filename)); ticketAttachment.FilePath = "/Uploads/" + filename; } if (ticket.AssignedToUserId != null) { TicketNotificationHelper NotificationHelper = new TicketNotificationHelper(); await NotificationHelper.SendNotificationAsync("File added ticket", "A attachment has been added to ticket", "Ticket Attachment", ticket.Id, ticket.AssignedToUserId); } db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { Id = TicketId })); } return(RedirectToAction("Details", "Tickets", new { Id = TicketId })); }
public async Task <ActionResult> Create([Bind(Include = "TicketId,CommentBody")] TicketComment ticketComment) { if (ModelState.IsValid) { ticketComment.UserId = User.Identity.GetUserId(); ticketComment.Created = DateTime.Now; db.TicketComments.Add(ticketComment); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { Id = ticketComment.TicketId })); } var ticket = db.Tickets.Find(ticketComment.TicketId); TicketNotificationHelper NotificationHelper = new TicketNotificationHelper(); await NotificationHelper.SendNotificationAsync("Comment added ticket", "A comment has been added to ticket", "Ticket Attachment", ticket.Id, ticket.AssignedToUserId); ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketComment.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketComment.UserId); return(View(ticketComment)); }