public ActionResult attachToTicket(HttpPostedFileBase upload, TicketAttachment ticketAttachment) { if (upload != null && upload.ContentLength > 0) { if (!FileExtensionHelper.HasDocumentExtension(upload.FileName) && !FileExtensionHelper.HasImageExtension(upload.FileName)) { TempData["UploadError"] = "Invalid file extension"; return RedirectToAction("Details", new { Id = ticketAttachment.TicketsId }); } } if (upload != null) { var filePath = "/Uploads/"; var absPath = Server.MapPath("~" + filePath); Directory.CreateDirectory(absPath); ticketAttachment.FileUrl = filePath + upload.FileName; upload.SaveAs(Path.Combine(absPath, upload.FileName)); ticketAttachment.Created = DateTimeOffset.Now; ticketAttachment.UserId = User.Identity.GetUserId(); db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); } return RedirectToAction("Details", new { Id = ticketAttachment.TicketsId }); }
// GET: TicketAttachments/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TicketAttachment ticketAttachment = db.TicketAttachments.Find(id); if (ticketAttachment == null) { return(HttpNotFound()); } return(View(ticketAttachment)); }
// GET: TicketAttachments/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TicketAttachment ticketAttachment = db.TicketAttachments.Find(id); if (ticketAttachment == null) { return(HttpNotFound()); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "OwnerUserId", ticketAttachment.TicketId); return(View(ticketAttachment)); }
public ActionResult Edit([Bind(Include = "Id,Description,Created,TicketId,UserId,FileUrl")] TicketAttachment ticketAttachment, HttpPostedFileBase attachment) { if (ModelState.IsValid) { if (attachment != null && attachment.ContentLength > 0) { if (FileUploadValidator.IsWebFriendlyFile(attachment)) { var fileName = Path.GetFileName(attachment.FileName); attachment.SaveAs(Path.Combine(Server.MapPath("~/Content/Uploads"), fileName)); ticketAttachment.FileUrl = "~/Content/Uploads/" + fileName; db.TicketAttachments.Add(ticketAttachment); } } db.Entry(ticketAttachment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "title", ticketAttachment.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId); return(View(ticketAttachment)); }
public ActionResult Create([Bind(Include = "Id,Title,Description,Created,Updated,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,AssignedToUserId")] Tickets tickets, TicketAttachment ticketAtt) { if (ModelState.IsValid) { tickets.Created = DateTimeOffset.Now; tickets.OwnerUserId = User.Identity.GetUserId(); db.Tickets.Add(tickets); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", tickets.ProjectId); ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", tickets.TicketPriorityId); ViewBag.TicketStatusId = new SelectList(db.TicketType, "Id", "Name", tickets.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketType, "Id", "Name", tickets.TicketTypeId); ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "FirstName"); return View(tickets); }
public ActionResult Details(int Id, string allowed, string AttachDesc, HttpPostedFileBase fileUpload) { var ticket = db.Tickets.Find(Id); ViewBag.CreateAllowed = true; if (ModelState.IsValid) { if (fileUpload != null && fileUpload.ContentLength > 0 && allowed == "true") { var attachment = new TicketAttachment(); var userId = User.Identity.GetUserId(); attachment.TicketId = Id; attachment.Description = AttachDesc; var fileName = Path.GetFileName(fileUpload.FileName); attachment.Created = DateTimeOffset.UtcNow; attachment.UserId = userId; attachment.FilePath = Path.Combine(Server.MapPath("~/Uploads/"), fileName); fileUpload.SaveAs(attachment.FilePath); attachment.FileUrl = "~/Uploads/" + fileName; db.TicketAttachments.Add(attachment); db.SaveChanges(); if (ticket.AssignedToUserId != null && ticket.AssignedToUserId != userId) { var subject = "A Ticket Assigned to You Has Been Modified"; SendNotification(ticket.AssignedToUserId, ticket.Id, subject); } } } return View(ticket); }