Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // GET: Edit/5
- public ActionResult Edit(string id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- ApplicationUser applicationUser = db.Users.Find(id);
- if (applicationUser == null)
- {
- return HttpNotFound();
- }
- return View(applicationUser);
- }
- // POST: Edit/5
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<ActionResult> Edit([Bind(Include = "Id, EmployeeNumber, FirstName, LastName, Department, Supervisor, Email, UserName, Password, Confirm Password")] ApplicationUser applicationUser)
- {
- if (ModelState.IsValid)
- {
- var user = await UserManager.FindByNameAsync(applicationUser.Email);
- applicationUser.SecurityStamp = Guid.NewGuid().ToString("D");
- string resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
- var pass = Request["Password"];
- IdentityResult passwordChangeResult = await UserManager.ResetPasswordAsync(user.Id, resetToken, Request["Password"]);
- db.Entry(applicationUser).State = EntityState.Modified;
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- return View(applicationUser);
- }
- namespace ReconciliationApp.Models
- {
- public class ApplicationUser : IdentityUser
- {
- public string EmployeeNumber { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Department { get; set; }
- public string Supervisor { get; set; }
- public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
- {
- // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
- var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
- // Add custom user claims here
- return userIdentity;
- }
- }
- public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
- {
- public ApplicationDbContext() : base("ReconciliationContext")
- {
- }
- public static ApplicationDbContext Create()
- {
- return new ApplicationDbContext();
- }
- public System.Data.Entity.DbSet<ReconciliationApp.Models.RegisterViewModel> RegisterViewModels { get; set; }
- }
- }
- // POST: CSReconForms/Edit/5
- // To protect from overposting attacks, please enable the specific properties you want to bind to, for
- // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<ActionResult> Edit([Bind(Include = "Id, EmployeeNumber, FirstName, LastName, Department, Supervisor, Email, UserName, Password, Confirm Password")] ApplicationUser applicationUser)
- {
- if (ModelState.IsValid)
- {
- //UserManager.Create<applicationu>();
- var user = await UserManager.FindByNameAsync(applicationUser.Email);
- //applicationUser.SecurityStamp = Guid.NewGuid().ToString("D");
- user.EmployeeNumber = applicationUser.EmployeeNumber;
- user.FirstName = applicationUser.FirstName;
- user.LastName = applicationUser.LastName;
- user.Department = applicationUser.Department;
- user.Supervisor = applicationUser.Supervisor;
- string resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
- var pass = Request["Password"];
- IdentityResult passwordChangeResult = await UserManager.ResetPasswordAsync(user.Id, resetToken, Request["Password"]);
- return RedirectToAction("Index");
- }
- return View(applicationUser);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement