public ViewResult Register(CustomerViewModel customerViewModel) { if (ModelState.IsValid) { customerViewModel.GeneratePasswordHash(); if (!repository.AddCustomer(customerViewModel.Customer)) { return(View()); } Customer customer = repository.Customers.Single(c => (c.Email == customerViewModel.Email && c.PasswordHash == customerViewModel.PasswordHash)); SaveCustomer(new CustomerViewModel(customer)); ViewBag.Customer = GetCustomer(); return(Customers()); } else //invalid { return(View()); } }
public ViewResult Register(CustomerViewModel customerViewModel) { if (ModelState.IsValid) //valid { customerViewModel.GeneratePasswordHash(); if (!repository.AddCustomer(customerViewModel.Customer)) //returns false if already there { return(View()); } //make sure the customer was added correctly before saving the session Customer customer = repository.Customers.Single(c => (c.Email == customerViewModel.Email && c.PasswordHash == customerViewModel.PasswordHash)); SaveCustomer(new CustomerViewModel(customer)); ViewBag.Customer = GetCustomer(); return(Customers()); } else //invalid { return(View()); } }