public ActionResult NewAccount(NewAccountModel newAccountModel) { if (ModelState.IsValid) { var service = new AccountService(); try { service.AddNewUser(newAccountModel); FormsAuthentication.RedirectToLoginPage(); } catch (UpdateException updateEx) { var sqlEx = updateEx.InnerException as SqlException; ModelState.AddModelError("NewUserError", sqlEx.Number == 2601 ? "This UserName is already used by another user" : "Database error while creating new user"); } catch (Exception ex) { ModelState.AddModelError("NewUserError", "Unknown error while creating new user"); } } return View(newAccountModel); }
public void TestVerifyUser(string message, LoginModel loginModel, bool expected) { var service = new AccountService { UserRepository = new FakeUserRepository() }; var result = service.VerifyUser(loginModel); Assert.AreEqual(expected, result); }
public CartModel GetCart() { CartModel cart = new CartModel { CartItems = GetCartFromSession().Select(kp => kp.Value) }; cart.SubTotal = cart.CartItems.Sum(item => item.ItemTotal); var user = new AccountService().UserRepository.FindByUserName(HttpContext.Current.User.Identity.Name); CalculateOrder(user, cart); return cart; }
public ActionResult Index(LoginModel loginModel) { if (ModelState.IsValid) { var service = new AccountService(); if (service.VerifyUser(loginModel)) { FormsAuthentication.SetAuthCookie(loginModel.UserName, false); return Redirect(Request.QueryString["ReturnUrl"] ?? "~/"); } ModelState.AddModelError("InvalidLogin","Invalid Login"); } return View(loginModel); }