示例#1
0
 public ActionResult Create([Bind(Include = "TicketId,Description")] TicketAttachment ticketAttachment, HttpPostedFileBase attachment, int ticketId)
 {
     if (attachment == null)
     {
         return(View(ticketAttachment));
     }
     if (ModelState.IsValid)
     {
         if (FileUtilities.AllowedFileType(attachment.FileName))
         {
             var fileName = Path.GetFileName(attachment.FileName);
             attachment.SaveAs(Path.Combine(Server.MapPath("/Uploads/"), fileName));
             ticketAttachment.FilePath = "/Uploads/" + fileName;
         }
         ticketAttachment.TicketId = ticketId;
         ticketAttachment.UserId   = User.Identity.GetUserId();
         ticketAttachment.Created  = DateTime.Now;
         db.TicketAttachments.Add(ticketAttachment);
         db.SaveChanges();
         NotificationManager.ManageAttachmentNotifications(ticketAttachment);
         return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId }));
     }
     ViewBag.TicketId = new SelectList(db.Tickets, "Id", "DeveloperId", ticketAttachment.TicketId);
     ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId);
     return(View(ticketAttachment));
 }