Advertisement
Guest User

Untitled

a guest
Jul 21st, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. // GET: Edit/5
  2. public ActionResult Edit(string id)
  3. {
  4. if (id == null)
  5. {
  6. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  7. }
  8.  
  9. ApplicationUser applicationUser = db.Users.Find(id);
  10. if (applicationUser == null)
  11. {
  12. return HttpNotFound();
  13. }
  14. return View(applicationUser);
  15. }
  16.  
  17. // POST: Edit/5
  18. [HttpPost]
  19. [ValidateAntiForgeryToken]
  20. public async Task<ActionResult> Edit([Bind(Include = "Id, EmployeeNumber, FirstName, LastName, Department, Supervisor, Email, UserName, Password, Confirm Password")] ApplicationUser applicationUser)
  21. {
  22. if (ModelState.IsValid)
  23. {
  24. var user = await UserManager.FindByNameAsync(applicationUser.Email);
  25. applicationUser.SecurityStamp = Guid.NewGuid().ToString("D");
  26. string resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
  27. var pass = Request["Password"];
  28. IdentityResult passwordChangeResult = await UserManager.ResetPasswordAsync(user.Id, resetToken, Request["Password"]);
  29.  
  30. db.Entry(applicationUser).State = EntityState.Modified;
  31. db.SaveChanges();
  32. return RedirectToAction("Index");
  33. }
  34. return View(applicationUser);
  35. }
  36.  
  37. namespace ReconciliationApp.Models
  38. {
  39. public class ApplicationUser : IdentityUser
  40. {
  41. public string EmployeeNumber { get; set; }
  42. public string FirstName { get; set; }
  43. public string LastName { get; set; }
  44. public string Department { get; set; }
  45. public string Supervisor { get; set; }
  46.  
  47. public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
  48. {
  49. // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
  50. var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
  51. // Add custom user claims here
  52. return userIdentity;
  53. }
  54. }
  55.  
  56. public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
  57. {
  58. public ApplicationDbContext() : base("ReconciliationContext")
  59. {
  60. }
  61.  
  62. public static ApplicationDbContext Create()
  63. {
  64. return new ApplicationDbContext();
  65. }
  66.  
  67. public System.Data.Entity.DbSet<ReconciliationApp.Models.RegisterViewModel> RegisterViewModels { get; set; }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement