public ActionResult Create(int projectId, int ticketId, NewTicketAttachmentViewModel model) { if (ModelState.IsValid) { TicketAttachment ticketAttachment = new TicketAttachment() { TicketID = ticketId, UserID = User.Identity.GetUserId(), Created = System.DateTimeOffset.Now, Description = model.Description }; // Create this new directory if it doesn't already exist. string directory = Server.MapPath(String.Format(@"~/Uploads/Project{0}/Ticket{1}/Attachments/", projectId, ticketId)); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string FileName = model.Attachment.FileName; string FileContentType = model.Attachment.ContentType; string FilePath = directory + FileName; model.Attachment.SaveAs(FilePath); ticketAttachment.DataFilePath = FilePath; db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); TempData["tab"] = "#attachments-3"; return(RedirectToAction("Show", "Tickets", new { projectId = projectId, id = ticketId })); } return(View("New", model)); }
// GET: users/{accountUsername}/projects/{projectId}/tickets/{ticketId}/ticketattachments/new public ActionResult New(string accountUsername, int projectId, int ticketId) { ViewBag.UserName = accountUsername; ViewBag.ProjectID = projectId; ViewBag.TicketID = ticketId; NewTicketAttachmentViewModel model = new NewTicketAttachmentViewModel(); return(View(model)); }