예제 #1
0
        public async Task <ActionResult> Create([Bind(Include = "Id,TicketId,Description,Created,UserId,FileUrl")] TicketAttachment ticketAttachment, HttpPostedFileBase attachment)
        {
            if (ModelState.IsValid)
            {
                if (FileUploadValidator.IsWebFriendlyFile(attachment))
                {
                    var fileName = Path.GetFileName(attachment.FileName);
                    attachment.SaveAs(Path.Combine(Server.MapPath("~/Content/Uploads"), fileName));
                    ticketAttachment.FileUrl = "~/Content/Uploads/" + fileName;
                    ticketAttachment.Created = DateTime.Now;
                    db.TicketAttachments.Add(ticketAttachment);
                    db.SaveChanges();

                    // begin notification functionality
                    var ticket         = db.Tickets.Find(ticketAttachment.TicketId);
                    var attacher       = db.Users.Find(ticketAttachment.UserId).FirstName + " " + db.Users.Find(ticketAttachment.UserId).LastName;
                    var assignedUserId = ticket.AssignedToUserId;
                    if (assignedUserId != null)
                    {
                        await notificationHelper.AttachmentNotification(ticketAttachment.TicketId, assignedUserId, ticket.title, fileName, attacher);
                    }
                    // end notification
                    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));
        }
예제 #2
0
 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));
 }