Beispiel #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                using (ClothesShopEntities entities = new ClothesShopEntities())
                {
                    if (entities.Users.Where(x => x.Username == model.UserName).Count() > 0)
                    {
                        ModelState.AddModelError("", "Username already exists");
                        return View(model);
                    }

                    ClothesShop.User user = new ClothesShop.User();
                    user.Username = model.UserName;
                    user.Password = model.Password;
                    user.IsAdmin = false;
                    entities.Users.AddObject(user);
                    entities.SaveChanges();

                    Session["Username"] = user.Username;
                    Session["IsAuthenticated"] = true;
                    return RedirectToAction("Index", "Home");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Beispiel #2
0
 public ActionResult Register(RegisterModel model)
 {
     if (ModelState.IsValid)
     {
         var result = _userRepository.InsertUser(model.Password, model.Email, model.Gender, model.Birthday,
                                                 model.Firstname, model.Lastname, model.Phone, null);
         if (result.Result)
         {
             SessionManager.UserIsLoggedIn = true;
             var user = _userRepository.Login(model.Email, model.Password);
             SessionManager.UserLogin = user;
             return RedirectToAction("index", "home");
         }
         ModelState.AddModelError("", result.Message);
     }
     return View(model);
 }