public ActionResult Create([Bind(Include = "TicketId,Descriptionn")] TicketAttachment ticketAttachment, HttpPostedFileBase file, string Descriptionn) { if (ModelState.IsValid) { if (file != null) { if (UploadValidator.IsWebFriendlyFile(file) || UploadValidator.IsWebFriendlyImage(file)) { var fileName = Path.GetFileName(file.FileName); var onlyFilename = Path.GetFileNameWithoutExtension(fileName); onlyFilename = StringUtilities.URLFriendly(onlyFilename); fileName = $"{onlyFilename}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; file.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttachment.MediaUrl = "/Uploads/" + fileName; ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); ticketAttachment.Description = Descriptionn; db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); } } return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); //return View("Index"); } return(View(ticketAttachment)); }
public ActionResult Create([Bind(Include = "TicketId,Description")] TicketAttachment ticketAttachment, HttpPostedFileBase attachments) { if (ModelState.IsValid) { if (attachments != null) { if (UploadValidator.IsWebFriendlyImage(attachments) || UploadValidator.IsWebFriendlyFile(attachments)) { var fileName = Path.GetFileName(attachments.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; attachments.SaveAs(Path.Combine(Server.MapPath("~/Attachments/"), fileName)); ticketAttachment.FilePath = "/Attachments/" + fileName; ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); } } var tkAttach = db.Tickets.Find(ticketAttachment.TicketId).Id; return(RedirectToAction("Details", "Tickets", new { id = tkAttach })); } return(View(ticketAttachment)); }
public ActionResult Create([Bind(Include = "TicketId,Description")] TicketAttachment ticketAttachment, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { if (UploadValidator.IsWebFriendlyImage(file) || UploadValidator.IsWebFriendlyFile(file)) { var fileName = Path.GetFileName(file.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); var ticketId = ticketAttachment.TicketId; var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticketId); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; file.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttachment.FilePath = "/Uploads/" + fileName; ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); //=========================== Ticket History ======================================= oldTicket.Updated = DateTime.Now; //ticketAttachment.Ticket.Updated = DateTime.Now; var newTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticketId); db.Entry(oldTicket).State = EntityState.Modified; db.TicketAttachments.Add(ticketAttachment); auditHelper.RecordAttachments(oldTicket, newTicket, fileName); // create notification notificationHelper.AttachmentNotification(newTicket); //=================================================================================== var userr = User.Identity.GetUserId(); if (!rolesHelper.IsDemoUser(userr)) { db.SaveChanges(); } } } //Response.Redirect(Request.RawUrl); return(RedirectToAction("Index", "Tickets", new { id = ticketAttachment.TicketId })); } return(View(ticketAttachment)); }