public ActionResult EditProfile(ApplicationUser user, HttpPostedFileBase avatar) { var currentUser = db.Users.Find(User.Identity.GetUserId()); if (user.FirstName == null) { currentUser.FirstName = currentUser.FirstName; } else { currentUser.FirstName = user.FirstName; } if (user.LastName == null) { currentUser.LastName = currentUser.LastName; } else { currentUser.LastName = user.LastName; } if (user.DisplayName == null) { currentUser.DisplayName = currentUser.DisplayName; } else { currentUser.DisplayName = user.DisplayName; } if (user.Email == null) { currentUser.Email = currentUser.Email; } else { currentUser.UserName = user.Email; currentUser.Email = user.Email; } if (avatar == null) { currentUser.AvatarPath = currentUser.AvatarPath; } else { //currentUser.AvatarPath = user.AvatarPath; if (FileUploadValidator.IsWebFriendlyImage(avatar)) { var fileName = Path.GetFileName(avatar.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars"), fileName)); user.AvatarPath = "/Avatars/" + fileName; currentUser.AvatarPath = user.AvatarPath; } } db.SaveChanges(); return(RedirectToAction("EditProfile", new { Message = ManageMessageId.EditProfileSuccess })); }
public ActionResult Create([Bind(Include = "Id,TicketId,Description,Created,UserId,FileUrl")] TicketAttachment ticketAttachment, HttpPostedFileBase file) { //if (ModelState.IsValid) //{ // db.TicketAttachments.Add(ticketAttachment); // db.SaveChanges(); // return RedirectToAction("Index"); //} if (ModelState.IsValid) { if (FileUploadValidator.IsWebFriendlyImage(file)) { var fileName = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(Server.MapPath("~/Files/Uploads/"), fileName)); ticketAttachment.FileUrl = "/Files/Uploads/" + fileName; } ticketAttachment.UserId = User.Identity.GetUserId(); ticketAttachment.Created = DateTime.Now; db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); var ticket = db.Tickets.Find(ticketAttachment.TicketId); return(RedirectToAction("Details", "Tickets", new { id = ticket.Id })); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId); return(View(ticketAttachment)); }
public ActionResult Create([Bind(Include = "TicketId")] TicketAttach ticketAttach, HttpPostedFileBase file, string attachDesc) { if (ModelState.IsValid) { if (file != null) { if (FileUploadValidator.IsWebFriendlyImage(file) || FileUploadValidator.IsWebFriendlyFile(file)) { ticketAttach.Description = attachDesc; var fileName = Path.GetFileName(file.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; file.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttach.FilePath = "/Uploads/" + fileName; ticketAttach.Created = DateTime.Now; ticketAttach.UserId = User.Identity.GetUserId(); db.TicketAttaches.Add(ticketAttach); db.SaveChanges(); } } return(RedirectToAction("Details", "Ticket", new { Id = ticketAttach.TicketId })); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttach.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttach.UserId); return(View(ticketAttach)); }
public ActionResult Create([Bind(Include = "TicketId")] TicketAttachment ticketAttachment, string AttachmentDescription, HttpPostedFileBase file) { var notificationHelper = new NotificationHelper(); var projHelper = new ProjectHelper(); if (ModelState.IsValid) { if (FileUploadValidator.IsWebFriendlyImage(file)) { var fileName = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttachment.FilePath = "/Uploads/" + fileName; } ticketAttachment.Description = AttachmentDescription; ticketAttachment.UserId = User.Identity.GetUserId(); ticketAttachment.Created = DateTime.Now; db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); notificationHelper.GetAttachmentNotification(ticketAttachment.TicketId); 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)); }
public async Task <ActionResult> Create([Bind(Include = "Id, TicketId,FilePath,Description,UserId,FileUrl")] TicketAttachments ticketAttachments, HttpPostedFileBase attachment) { var ticketHistory = new TicketHistories(); var tickets = new Tickets(); var user = User.Identity.GetUserId(); var currentUser = db.Users.Find(user); //var ticketId = db.Tickets.FirstOrDefault(t => t.OwnerUserId == user).Id; var ticketOwnerId = db.Tickets.FirstOrDefault(t => t.OwnerUserId == user); ticketAttachments.UserId = currentUser.Id; if (FileUploadValidator.IsWebFriendlyFile(attachment)) { var absPath = Path.GetFileName(attachment.FileName); attachment.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), absPath)); ticketAttachments.FileUrl = "~/Uploads/" + absPath; if (ModelState.IsValid) { //Send Notification var developer = db.Users.Find(tickets.AssignedToUserId); if (developer != null && developer.Email != null) { var svc = new EmailService(); var msg = new IdentityMessage(); msg.Destination = developer.Email; msg.Subject = "Bug Tracker Update: " + tickets.Title; msg.Body = ("An attachment has been added to Ticket ID: " + tickets.Id + " - " + tickets.Title); await svc.SendAsync(msg); } //Ticket History ticketHistory.TicketId = ticketAttachments.TicketId; ticketHistory.Property = "Added Attachment"; ticketHistory.NewValue = "Added"; ticketHistory.UserId = ticketAttachments.UserId; ticketHistory.ChangeDate = DateTime.Now; ticketAttachments.Created = DateTime.Now; db.TicketHistories.Add(ticketHistory); db.TicketAttachments.Add(ticketAttachments); db.SaveChanges(); return(RedirectToAction("Index", "Tickets", new { id = ticketAttachments.TicketId })); } } else { ModelState.AddModelError("attachment", "Invalid Format."); } // } //} ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachments.Id); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachments.UserId); return(View(ticketAttachments)); }
public async Task <ActionResult> Index(ApplicationUser model, HttpPostedFileBase image) { FileUploadValidator fileHelper = new FileUploadValidator(); var userId = User.Identity.GetUserId(); model = db.Users.AsNoTracking().FirstOrDefault(u => u.Id == userId); if (fileHelper.IsWebpageFrendlyFile(image)) { TempData["avatarCheck"] = "Success"; var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Avatar/"), fileName)); model.avatar = "/Avatar/" + fileName; } else { TempData["avatarCheck"] = "Failure"; } db.Users.Attach(model); db.Entry(model).State = EntityState.Modified; db.SaveChanges(); var viewModel = new IndexViewModel { HasPassword = HasPassword(), currentUser = UserManager.FindById(userId), PhoneNumber = await UserManager.GetPhoneNumberAsync(userId), TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId), Logins = await UserManager.GetLoginsAsync(userId), BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId) }; return(View(viewModel)); }
public ActionResult Create([Bind(Include = "Id,TicketId,FilePath,Description,Created,UserId")] TicketAttachment ticketAttachment, HttpPostedFileBase image) { var oldTicketAttachment = db.TicketAttachments.AsNoTracking().FirstOrDefault(t => t.Id == ticketAttachment.TicketId); if (ModelState.IsValid) { if (FileUploadValidator.IsWebFriendlyFile(image)) { var fileName = Path.GetFileName(image.FileName).Replace(' ', '_'); image.SaveAs(Path.Combine(Server.MapPath("~/FilesUploaded/"), fileName)); ticketAttachment.FilePath = "/FilesUploaded/" + fileName; } ticketAttachment.Created = DateTimeOffset.Now; ticketAttachment.UserId = User.Identity.GetUserId(); ticketAttachment.User = db.Users.Find(ticketAttachment.UserId); ticketAttachment.Ticket = db.Tickets.Find(ticketAttachment.TicketId); db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); ticketAttachment.AttachmentAdded(oldTicketAttachment); 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)); }
public ActionResult Create([Bind(Include = "Id,TicketId,Description,Created,UserId,FileUrl")] TicketAttachment ticketAttachment, HttpPostedFileBase file) { if (ModelState.IsValid) { if (FileUploadValidator.IsWebFriendlyFile(file)) { var fileName = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(Server.MapPath("~/img/"), fileName)); ticketAttachment.FileUrl = "~/img/" + fileName; var ticketHistory = new TicketHistory(); var oldTicketAttachment = db.TicketAttachments.Find(ticketAttachment.Id); ticketHistory.Changed = DateTime.Now; ticketHistory.NewValue = ticketAttachment.FileUrl; ticketHistory.Property = "Ticket Attachment"; ticketHistory.TicketId = ticketAttachment.TicketId; ticketHistory.UserId = User.Identity.GetUserId(); db.TicketHistories.Add(ticketHistory); ticketAttachment.Created = DateTime.Now; db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); } return(RedirectToAction("Index", "Tickets")); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId); return(View("Details", "Tickets", new { id = ticketAttachment.TicketId })); }
public ActionResult Create([Bind(Include = "TicketId")] TicketAttachment ticketAttachment, HttpPostedFileBase attach, string aDescription) { if (ModelState.IsValid) { if (FileUploadValidator.IsWebFriendlyImage(attach) || FileUploadValidator.IsWebFriendlyFile(attach)) { var fileName = Path.GetFileName(attach.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; attach.SaveAs(Path.Combine(Server.MapPath("~/Attachments"), fileName)); ticketAttachment.FilePath = "/Attachments/" + fileName; ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); ticketAttachment.Description = aDescription; nHelp.AddAttachmentNotification(ticketAttachment); db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); } } return(View(ticketAttachment)); }
public ActionResult Create([Bind(Include = "TicketId,Body")] TicketAttachment ticketAttachment, HttpPostedFileBase file) { if (ModelState.IsValid) { ticketAttachment.CreatedDate = DateTime.Now; ticketAttachment.OwnerId = User.Identity.GetUserId(); if (file != null) { if (FileUploadValidator.IsWebFriendlyFile(file) || ImageUploadValidator.IsWebFriendlyImage(file)) { var fileName = Path.GetFileName(file.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; file.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttachment.FilePath = "/Uploads/" + fileName; ticketAttachment.CreatedDate = DateTime.Now; ticketAttachment.OwnerId = User.Identity.GetUserId(); db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); } } return(RedirectToAction("Index", "TicketAttachments", new { id = ticketAttachment.TicketId })); } return(View(ticketAttachment)); }
public ActionResult Create([Bind(Include = "TicketId,FileName,Description")] TicketAttachment ticketAttachment, HttpPostedFileBase file) { if (ModelState.IsValid) { ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); if (file == null) { TempData["Error"] = "You must supply a file."; return(RedirectToAction("Dashboard", "Tickets", new { id = ticketAttachment.TicketId })); } if (FileUploadValidator.IsWebFriendlyImage(file) || FileUploadValidator.IsWebFriendlyFile(file)) { var fileName = FileStamp.MakeUnique(file.FileName); var serverFolder = WebConfigurationManager.AppSettings["DefaultServerFolder"]; file.SaveAs(Path.Combine(Server.MapPath(serverFolder), fileName)); ticketAttachment.FilePath = $"{serverFolder}{fileName}"; } db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); var ticket = db.Tickets.Find(ticketAttachment.TicketId); if (ticket.DeveloperId != User.Identity.GetUserId()) { ticketManager.AttachmentNotifications(ticket); } return(RedirectToAction("Dashboard", "Tickets", new { id = ticketAttachment.TicketId })); } TempData["Error"] = "The model was invalid."; return(RedirectToAction("Dashboard", "Tickets", new { id = ticketAttachment.TicketId })); }
public ActionResult UploadFileToTicket([Bind(Include = "TicketId,FileName")] TicketAttachment ticketAttachments, string AttachmentDescription, HttpPostedFileBase file) { if (file == null) { TempData["Error"] = "You must Supply a vaild File"; return(RedirectToAction("Dashboard", "Tickets", new { id = ticketAttachments.TicketId })); } if (ModelState.IsValid) { if (FileUploadValidator.IsWebFriendlyImage(file) || FileUploadValidator.IsWebFriendlyFile(file)) { ticketAttachments.Created = DateTime.Now; ticketAttachments.UserId = User.Identity.GetUserId(); ticketAttachments.Description = AttachmentDescription; var fileName = FileStamp.MakeUnique(file.FileName); var serverFolder = WebConfigurationManager.AppSettings["DefaultAttachmentFolder"]; file.SaveAs(Path.Combine(Server.MapPath(serverFolder), fileName)); ticketAttachments.FilePath = $"{serverFolder}{fileName}"; ticketAttachments.FileName = fileName; db.TicketAttachments.Add(ticketAttachments); db.SaveChanges(); notificationHelper.TicketNewAttachmentAdded(ticketAttachments); return(RedirectToAction("Dashboard", "Tickets", new { id = ticketAttachments.TicketId })); } } //ViewBag.TicketId = new SelectList(db.Tickets, "Id", "SubmitterId", ticketAttahment.TicketId); //ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttahment.UserId); TempData["Error"] = "Model Invalid"; return(RedirectToAction("Dashboard", "Tickets", new { id = ticketAttachments.TicketId })); }
public ActionResult Create([Bind(Include = "TicketId")] TicketAttachment ticketAttachment, HttpPostedFileBase filePath) { if (ModelState.IsValid) { if (FileUploadValidator.IsWebFriendlyImage(filePath)) { var fileName = Path.GetFileName(filePath.FileName); fileName = fileName.Replace(' ', '_'); filePath.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttachment.FilePath = "/Uploads/" + fileName; } ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "OwnerUserId", ticketAttachment.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId); return(View(ticketAttachment)); }
public async Task <ActionResult> Register(RegisterViewModel model, HttpPostedFileBase filePath) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.DisplayName, AvatarPath = model.Avatar }; if (FileUploadValidator.IsWebFriendlyImage(filePath)) { var fileName = Path.GetFileName(filePath.FileName); fileName = fileName.Replace(' ', '_'); filePath.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); model.Avatar = "/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); var body = "Please confirm your email by clicking <a href=\"" + callbackUrl + "\"> here.</a>"; var emailto = model.Email; var from = string.Format("BugTracker<*****@*****.**>"); var email = new MailMessage(from, emailto) { Subject = "Confirm your account", Body = body, IsBodyHtml = true }; var svc = new PersonalEmail(); await svc.SendAsync(email); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public static string UploadSingleFile(HttpPostedFileBase file) { if (FileUploadValidator.IsWebFriendlyImage(file) || FileUploadValidator.IsWebFriendlyFile(file)) { var fileName = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(HttpContext.Current.Server.MapPath("/Uploads/"), fileName)); return("/Uploads/" + fileName); } return(""); }
public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModelExtended model, string returnUrl) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Manage")); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return(View("ExternalLoginFailure")); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, AvatarPath = WebConfigurationManager.AppSettings["DefaultAvatarPath"] }; if (model.Avatar != null) { if (FileUploadValidator.IsWebFriendlyImage(model.Avatar)) { var fileName = FileStamp.MakeUnique(model.Avatar.FileName); var AvatarFolder = WebConfigurationManager.AppSettings["DefaultAvatarFolder"]; model.Avatar.SaveAs(Path.Combine(Server.MapPath(AvatarFolder), fileName)); user.AvatarPath = $"{AvatarFolder}{fileName}"; } } var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(RedirectToLocal(returnUrl)); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public ActionResult UploadAttachment([Bind(Include = "Id,TicketId,FilePath,FileUrl,Description,Created")] TicketAttachment ticketattachment, HttpPostedFileBase file) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { // TempData["UserPreferences"] is read in at Start of Action var userPref = (UserPreferencesViewModel)TempData["UserPreferences"]; if (FileUploadValidator.IsWebFriendlyImage(file)) { var filename = Path.GetFileName(file.FileName); var customname = string.Format(Guid.NewGuid() + filename); file.SaveAs(Path.Combine(Server.MapPath("~/upload/"), customname)); ticketattachment.FileUrl = customname; } else { ViewBag.StatusMessage = "Acceptable file formats are: csv, xls, xlsx, doc, docx, jpg, png, txt, pdf"; ViewBag.FileErrorMsg = "Acceptable file formats are: csv, xls, xlsx, doc, docx, jpg, png, txt, pdf"; ticketattachment.FileUrl = "defaultImg.jpg"; // default image return(RedirectToAction("Details", new { id = ticketattachment.TicketId })); } ticketattachment.FilePath = "~/upload/"; ticketattachment.Created = DateTime.Now; ticketattachment.UserId = User.Identity.GetUserId(); db.TicketAttachments.Add(ticketattachment); db.SaveChanges(); TicketNotification ticketnotif = new TicketNotification(); ticketnotif.TicketId = ticketattachment.TicketId; ticketnotif.UserId = db.Tickets.Find(ticketnotif.TicketId).AssignedToUserId; var sendtoemail = db.Tickets.Find(ticketnotif.TicketId).AssignedToUser.Email; ticketnotif.Message = "A new attachment was uploaded to a ticket you are assigned to on BugTracker.Pro."; ticketnotif.Created = DateTime.Now; db.Entry(ticketnotif).State = EntityState.Modified; db.TicketNotifications.Add(ticketnotif); db.SaveChanges(); // TempData["UserPreferences"] is rewritten at End of Action TempData["UserPreferences"] = userPref; ViewBag.FilterByTickets = userPref.FilterByTickets; ViewBag.FilterByStatus = userPref.FilterByStatus; return(RedirectToAction("EmailNotification", "Account", new { sendemail = sendtoemail, sendmsg = ticketnotif.Message, ticketId = ticketnotif.TicketId })); } return(RedirectToAction("Details", new { id = ticketattachment.TicketId })); }
public async Task <ActionResult> AcceptInvitation(AcceptInvitationVM model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, HouseholdId = model.HouseholdId }; if (model.Avatar != null) { if (FileUploadValidator.IsWebFriendlyImage(model.Avatar)) { var fileName = FileStamp.MakeUnique(model.Avatar.FileName); var serverFolder = WebConfigurationManager.AppSettings["DefaultServerFolder"]; model.Avatar.SaveAs(Path.Combine(Server.MapPath("~" + serverFolder), fileName)); user.AvatarPath = $"{serverFolder}/{fileName}"; } } var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { rolesHelper.AddUserToRole(user.Id, "Member"); InvitationHelper.MarkAsInvalid(model.InvitationId); 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("Dashboard", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(ExtendedRegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, AvatarPath = "/Images/default_avatar.png" }; if (model.Avatar != null) { if (FileUploadValidator.IsWebFriendlyImage(model.Avatar)) { var fileName = FileStamp.MakeUnique(model.Avatar.FileName); model.Avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars"), fileName)); user.AvatarPath = "/Avatars/" + 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 Edit2([Bind(Include = "Id,FirstName, LastName, Email, AvatarPath, DisplayName,EmailConfirmed,PhoneNumber,PhoneNumberConfirmed")] ApplicationUser applicationUser, HttpPostedFileBase filePath, string roles) { if (ModelState.IsValid) { //1st get list of roles user occupies var currentRoles = roleHelper.ListUserRoles(applicationUser.Id); foreach (var role in currentRoles) { //Removes users from all and any role they occupy roleHelper.RemoveUserFromRole(applicationUser.Id, role); } if (!string.IsNullOrEmpty(roles)) { roleHelper.AddUserToRole(applicationUser.Id, roles); } if (FileUploadValidator.IsWebFriendlyImage(filePath)) { var fileName = Path.GetFileName(filePath.FileName); fileName = fileName.Replace(' ', '_'); filePath.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); applicationUser.AvatarPath = "/Uploads/" + fileName; } //db.Entry(applicationUser).State = EntityState.Modified; db.Users.Attach(applicationUser); applicationUser.UserName = applicationUser.Email; // times 7 for the properties that are subject to change, this allows for only for the ones to be changed instead of losing the information db.Entry(applicationUser).Property(x => x.FirstName).IsModified = true; db.Entry(applicationUser).Property(x => x.LastName).IsModified = true; db.Entry(applicationUser).Property(x => x.AvatarPath).IsModified = true; db.Entry(applicationUser).Property(x => x.Email).IsModified = true; db.Entry(applicationUser).Property(x => x.PhoneNumber).IsModified = true; db.Entry(applicationUser).Property(x => x.UserName).IsModified = true; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(applicationUser)); }
public ActionResult ManageUser(ManageUserVM userVM, string roleName, string projects) { List <Project> oldProjects = projectHelper.ListUserProjects(userVM.UserId).ToList(); var oldUser = db.Users.AsNoTracking().FirstOrDefault(u => u.Id == userVM.UserId); var user = db.Users.Find(userVM.UserId); user.Email = userVM.Email; user.UserName = userVM.Email; user.FirstName = userVM.FirstName; user.LastName = userVM.LastName; user.PhoneNumber = userVM.PhoneNumber; user.AvatarPath = userVM.AvatarPath; if (FileUploadValidator.IsWebFriendlyImage(userVM.Avatar)) { var fileName = FileStamp.MakeUnique(userVM.Avatar.FileName); var serverFolder = WebConfigurationManager.AppSettings["DefaultAvatarFolder"]; userVM.Avatar.SaveAs(Path.Combine(Server.MapPath(serverFolder), fileName)); user.AvatarPath = $"{serverFolder}{fileName}"; } db.SaveChanges(); projectHelper.updateUserProjects(userVM.UserId, userVM.ProjectIds); if (roleName != null) { foreach (var role in roleHelper.ListUserRoles(user.Id)) { roleHelper.RemoveUserFromRole(user.Id, role); } if (!string.IsNullOrEmpty(roleName)) { roleHelper.AddUserToRole(user.Id, roleName); } } var newUser = db.Users.AsNoTracking().FirstOrDefault(u => u.Id == userVM.UserId); historyHelper.CheckUserEdits(oldUser, newUser, oldProjects); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "TicketId")] TicketAttachment ticketAttachment, HttpPostedFileBase file, string attachmentDescription) { if (ModelState.IsValid) { //come back to this and finish it with some more help and figure it out if (FileUploadValidator.IsWebFriendlyImage(file)) { var fileName = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(Server.MapPath("~/Attachments/"), fileName)); ticketAttachment.FilePath = "/Attachments/" + fileName; } ticketAttachment.Description = attachmentDescription; ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); } return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); }
public ActionResult ChangeAvatar(HttpPostedFileBase image) { var userId = User.Identity.GetUserId(); var user = db.Users.Find(userId); if (FileUploadValidator.AvatarUploadValidator(image)) { var imageName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), imageName)); user.AvatarPath = "/Uploads/" + imageName; db.Users.Attach(user); db.Entry(user).Property(u => u.AvatarPath).IsModified = true; db.SaveChanges(); return(RedirectToAction("Index", "Manage")); } else { return(RedirectToAction("Index", "Manage")); } }
public static List <Tuple <string, string, string> > UploadMultipleFiles(HttpPostedFileBase[] files) { List <Tuple <string, string, string> > resultList = new List <Tuple <string, string, string> >(); if (files != null) { if (files.Length > 0) { foreach (var file in files) { if (FileUploadValidator.IsWebFriendlyImage(file) || FileUploadValidator.IsWebFriendlyFile(file)) { var fileName = Path.GetFileName(file.FileName); var iconName = ImageHelpers.GetIconPath(fileName); file.SaveAs(Path.Combine(HttpContext.Current.Server.MapPath("/Uploads/Attachments/"), fileName)); resultList.Add(new Tuple <string, string, string>(fileName, "/Uploads/Attachments/" + fileName, iconName)); } } } } return(resultList); }
public async Task <ActionResult> EditUser(UserProfileViewModel user, HttpPostedFileBase avatar) { if (ModelState.IsValid) { var myuser = db.Users.Find(user.Id); myuser.FirstName = user.FirstName; myuser.LastName = user.LastName; myuser.DisplayName = user.DisplayName; myuser.Email = user.Email; myuser.UserName = user.Email; if (avatar != null) { if (FileUploadValidator.IsWebFriendlyImage(avatar)) { var fileName = Path.GetFileName(avatar.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), fileName)); myuser.AvatarPath = "/Avatars/" + fileName; } } else { myuser.AvatarPath = user.AvatarPath; } db.SaveChanges(); await HttpContext.RefreshAuthentication(myuser); return(RedirectToAction("Dashboard", "Home")); } else { TempData["Errors"] = ErrorReader.ErrorCompiler(ModelState); return(RedirectToAction("EditUser")); } }
public async Task <ActionResult> Create([Bind(Include = "TicketId,FileName")] TicketAttachment ticketAttachment, HttpPostedFileBase file) { if (ModelState.IsValid) { ticketAttachment.Ticket = db.Tickets.Find(ticketAttachment.TicketId); var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticketAttachment.TicketId); db.Entry(ticketAttachment.Ticket).State = EntityState.Modified; if (ticketAttachment.FileName == null) { TempData["Error"] = "You must supply a File Name of at least three characters"; return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); } ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); if (file == null) { TempData["Error"] = "You must supply a file"; return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); } if (FileUploadValidator.IsWebFriendlyFile(file) || ImageUploadValidator.IsWebFriendlyImage(file)) { var fileName = FileStamp.MakeUnique(file.FileName); var serverFolder = WebConfigurationManager.AppSettings["DefaultServerFolder"]; file.SaveAs(Path.Combine(Server.MapPath(serverFolder), fileName)); ticketAttachment.FilePath = $"{serverFolder}{fileName}"; db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); var newTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticketAttachment.TicketId); await ticketHelper.ManageTicketNotifications(oldTicket, newTicket, "no"); } return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); } TempData["Error"] = "The Model State was invalid. I apologize"; return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); }
public async Task <ActionResult> ChangeAvatar(IndexViewModel model) { if (!ModelState.IsValid) { return(View("Index", model)); } var result = new IdentityResult(); var cUser = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (cUser != null) { if (FileUploadValidator.IsWebFriendlyImage(model.AvatarFile)) { var fileName = Path.GetFileName(model.AvatarFile.FileName); model.AvatarFile.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); cUser.AvatarUrl = "~/Uploads/" + fileName; } result = await UserManager.UpdateAsync(cUser); return(RedirectToAction("Index", new { Message = ManageMessageId.ChangeAvatarSuccess })); } var userId = User.Identity.GetUserId(); model.HasPassword = HasPassword(); model.PhoneNumber = await UserManager.GetPhoneNumberAsync(userId); model.TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId); model.Logins = await UserManager.GetLoginsAsync(userId); model.BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId); model.HasFirstName = HasFirstName(); model.HasLastName = HasLastName(); AddErrors(result); return(View("Index", model)); }
public ActionResult Create([Bind(Include = "Id,TicketId,FilePath,Description,CreatedDate,UserId")] TicketAttach ticketAttach, HttpPostedFileBase FileUrl, string description) { if (ModelState.IsValid) { if (FileUploadValidator.IsWebFriendlyFile(FileUrl)) { var fileName = Path.GetFileName(FileUrl.FileName); FileUrl.SaveAs(Path.Combine(Server.MapPath("~/Uploads"), fileName)); ticketAttach.FileUrl = "~/Uploads/" + fileName; } ticketAttach.CreatedDate = DateTime.Now; ticketAttach.Description = description; db.TicketAttachs.Add(ticketAttach); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = ticketAttach.TicketId })); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttach.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttach.UserId); return(View(ticketAttach)); }
public ActionResult EditMy([Bind(Include = "Id,FirstName,LastName,DisplayName,AvatarPath,Email,SecurityStamp,PhoneNumber,PasswordHash,UserName")] ApplicationUser applicationUser, string roles, HttpPostedFileBase image) { if (User.Identity.GetUserId() == "db9a774b-807c-4b9b-9b22-34c191872996" || User.Identity.GetUserId() == "3eaa1491-7553-40fa-b7e1-b994e05d05e0" || User.Identity.GetUserId() == "5f84068f-4213-4d02-81a4-21936ae10cdc" || User.Identity.GetUserId() == "60f316c5-536c-4f06-83d3-38a555febc29") { return(RedirectToAction("InvalidAttempt", "Home")); } if (ModelState.IsValid) { //since i might be changing the users role, i want to first remove from all roles var currentRoles = roleHelper.ListUserRoles(applicationUser.Id); foreach (var role in currentRoles) { roleHelper.RemoveUserFromRole(applicationUser.Id, role); } if (!string.IsNullOrEmpty(roles)) { roleHelper.AddUserToRole(applicationUser.Id, roles); } if (FileUploadValidator.IsWebFriendlyImage(image)) { var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); applicationUser.AvatarPath = "/Uploads/" + fileName; } applicationUser.UserName = applicationUser.Email; db.Entry(applicationUser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Profile")); } return(View(applicationUser)); }
public ActionResult Create([Bind(Include = "TicketId,FileName,Description")] TicketAttachment ticketAttachment, HttpPostedFileBase file) { if (file == null) { TempData["Error"] = "You must submit a file."; return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); } if (ModelState.IsValid) { //Pass it through a file validator if (FileUploadValidator.IsWebFriendlyFile(file)) { ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); var fileName = FileStamp.MakeUnique(file.FileName); //Assign the filePath property and save the physical file var serverFolder = WebConfigurationManager.AppSettings["DefaultAttachmentFolder"]; file.SaveAs(Path.Combine(Server.MapPath(serverFolder), fileName)); ticketAttachment.FilePath = $"{serverFolder}{fileName}"; db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); } return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); } TempData["Error"] = "The model is invalid."; return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.Ticket.Id })); //ViewBag.TicketId = new SelectList(db.Tickets, "Id", "SubmitterId", ticketAttachment.TicketId); //ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId); //return View(ticketAttachment); }