Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 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. }
  70.  
  71. // POST: CSReconForms/Edit/5
  72. // To protect from overposting attacks, please enable the specific properties you want to bind to, for
  73. // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
  74. [HttpPost]
  75. [ValidateAntiForgeryToken]
  76. public async Task<ActionResult> Edit([Bind(Include = "Id, EmployeeNumber, FirstName, LastName, Department, Supervisor, Email, UserName, Password, Confirm Password")] ApplicationUser applicationUser)
  77. {
  78. if (ModelState.IsValid)
  79. {
  80. //UserManager.Create<applicationu>();
  81. var user = await UserManager.FindByNameAsync(applicationUser.Email);
  82. //applicationUser.SecurityStamp = Guid.NewGuid().ToString("D");
  83. user.EmployeeNumber = applicationUser.EmployeeNumber;
  84. user.FirstName = applicationUser.FirstName;
  85. user.LastName = applicationUser.LastName;
  86. user.Department = applicationUser.Department;
  87. user.Supervisor = applicationUser.Supervisor;
  88.  
  89. string resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
  90. var pass = Request["Password"];
  91. IdentityResult passwordChangeResult = await UserManager.ResetPasswordAsync(user.Id, resetToken, Request["Password"]);
  92.  
  93. return RedirectToAction("Index");
  94. }
  95. return View(applicationUser);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement