Esempio n. 1
0
 public RedirectToRouteResult PasswordEdit(RegisterUserViewModel registerUserViewModel)
 {
     using (ShopDbDataContext db = new ShopDbDataContext())
     {
         var userToChangePassword = db.ApplicationUsers.First(u => u.Id == registerUserViewModel.Id);
         userToChangePassword.PasswordHash = registerUserViewModel.GetPasswordHash();
         db.SubmitChanges();
     }
     return(RedirectToAction("UserEdit", "Admin"));
 }
Esempio n. 2
0
 public ActionResult UserAdd(RegisterUserViewModel user)
 {
     if (Session["userId"] == null || Session["isAdmin"].ToString() == false.ToString())
     {
         return(RedirectToAction("Index", "Shop"));
     }
     if (ModelState.IsValid)
     {
         using (ShopDbDataContext db = new ShopDbDataContext())
         {
             var validateResult = user.Validate(db);
             if (validateResult.Count() > 0)  // В случае неуспешной валидации выводим ошибки
             {
                 foreach (string error in validateResult)
                 {
                     ModelState.AddModelError("", error);
                 }
                 return(View());
             }
             else
             {
                 ApplicationUsers newUser = new ApplicationUsers
                 {
                     UserName     = user.UserName,
                     PasswordHash = user.GetPasswordHash(),
                     Email        = user.Email,
                     PhoneNumber  = user.PhoneNumber,
                     Address      = user.Address,
                     IsAdmin      = user.IsAdmin
                 };
                 db.ApplicationUsers.InsertOnSubmit(newUser);
                 db.SubmitChanges();
                 return(RedirectToAction("Index", "Admin"));
             }
         }
     }
     else
     {
         return(View());
     }
 }
 public ActionResult Register(RegisterUserViewModel user)
 {
     if (ModelState.IsValid)
     {
         using (ShopDbDataContext db = new ShopDbDataContext())
         {
             var validateResult = user.Validate(db);
             if (validateResult.Count() > 0)  // В случае неуспешной валидации выводим ошибки
             {
                 foreach (string error in validateResult)
                 {
                     ModelState.AddModelError("", error);
                 }
                 return(View());
             }
             else
             {
                 ApplicationUsers newUser = new ApplicationUsers
                 {
                     UserName     = user.UserName,
                     PasswordHash = user.GetPasswordHash(),
                     Email        = user.Email,
                     PhoneNumber  = user.PhoneNumber,
                     Address      = user.Address
                 };
                 db.ApplicationUsers.InsertOnSubmit(newUser);
                 db.SubmitChanges();
                 return(RedirectToAction("Login", "Account"));
             }
         }
     }
     else
     {
         return(View());
     }
 }