public ActionResult Create([Bind(Include = "Id,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,AssignedToUserId,Title,Description,Created,Updated")] Tickets tickets, HttpPostedFileBase image, TicketAttachments ticketAttachment) { if (ModelState.IsValid) { if (UploadValidator.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 == tickets.ProjectId); tickets.Project = project; tickets.OwnerUserId = User.Identity.GetUserId(); tickets.Created = DateTime.Now; db.Tickets.Add(tickets); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "FirstName", tickets.AssignedToUserId); ViewBag.OwnerUserId = new SelectList(db.Users, "Id", "FirstName", tickets.OwnerUserId); ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", tickets.ProjectId); ViewBag.TicketStatusId = new SelectList(db.TicketStatus, "Id", "StatusName", tickets.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "TypeName", tickets.TicketTypeId); return(View(tickets)); }
public async Task <ActionResult> Register(RegisterViewModel model, HttpPostedFileBase avatar) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, DisplayName = model.DisplayName, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, AvatarPath = "/Avatars/default_user.Png" }; if (avatar != null) { if (UploadValidator.IsWebFriendlyAttachment(avatar)) { var filename = Path.GetFileName(avatar.FileName); var justFileName = Path.GetFileNameWithoutExtension(filename); justFileName = StringUtilities.URLFriendly(filename); filename = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(filename)}"; avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), filename)); user.AvatarPath = "/Uploads/" + filename; } } var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Create([Bind(Include = "Id,TicketId,FilePath,Description,UploadDate,UserId")] TicketAttachments ticketAttachments, HttpPostedFileBase image) { if (ModelState.IsValid) { if (UploadValidator.IsWebFriendlyAttachment(image)) { var filename = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), filename)); ticketAttachments.FilePath = "/Uploads/" + filename; } ticketAttachments.UploadDate = DateTime.Now; db.TicketAttachments.Add(ticketAttachments); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = ticketAttachments.TicketId })); } return(View(ticketAttachments)); }
public ActionResult EditProfile(AdminUser 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 (UploadValidator.IsWebFriendlyAttachment(avatar)) { var filename = Path.GetFileName(avatar.FileName); avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), filename)); user.AvatarPath = "/Avatars/" + filename; } } db.SaveChanges(); return(View()); }