public ActionResult Create([Bind(Include = "Id,Title,Description,Created,Updated,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,AssignedToUserId")] Ticket ticket, HttpPostedFileBase image, TicketAttachment ticketAttachment) { if (ModelState.IsValid) { if (AttachmentUploadValidator.IsWebFriendlyAttachment(image)) { var filename = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), filename)); ticketAttachment.FilePath = "/Uploads/" + filename; } var project = db.Projects.FirstOrDefault(p => p.Id == ticket.ProjectId); ticket.Project = project; ticket.OwnerUserId = User.Identity.GetUserId(); ticket.Created = DateTime.Now; db.Tickets.Add(ticket); db.SaveChanges(); return(RedirectToAction("Details", "Ticket")); //return RedirectToRoute("Details", "Ticket"); //return RedirectToAction("Index"); } ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "FirstName", ticket.AssignedToUserId); ViewBag.OwnerUserId = new SelectList(db.Users, "Id", "FirstName", ticket.OwnerUserId); ViewBag.ProjectId = new SelectList(db.Projects, "Id", "ProjectName", ticket.ProjectId); ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "PriorityName", ticket.TicketPriorityId); ViewBag.TicketStatusId = new SelectList(db.TicketStatuses, "Id", "StatusName", ticket.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "TypeName", ticket.TicketTypeId); return(View(ticket)); }
public ActionResult Create([Bind(Include = "Id,TicketId,FilePath,Description,Created,UserId")] TicketAttachment ticketAttachment, HttpPostedFileBase image) { if (ModelState.IsValid) { if (AttachmentUploadValidator.IsWebFriendlyAttachment(image)) { var filename = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), filename)); ticketAttachment.FilePath = "/Uploads/" + filename; } ticketAttachment.Created = DateTime.Now; db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); return(RedirectToAction("Index", "Tickets")); } return(View(ticketAttachment)); }
public ActionResult EditProfile(UserProfileViewModel model, HttpPostedFileBase avatar) { var userId = User.Identity.GetUserId(); var user = db.Users.Find(userId); user.DisplayName = model.DisplayName; user.FirstName = model.FirstName; user.LastName = model.LastName; user.Email = model.Email; if (avatar != null) { if (AttachmentUploadValidator.IsWebFriendlyAttachment(avatar)) { var filename = Path.GetFileName(avatar.FileName); avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), filename)); user.AvatarPath = "/Avatars/" + filename; } } db.SaveChanges(); return(View()); }