//Sign up - save the sign up date to the database public void AddUserAccount(UserModel user, AddressModel address) { using (ECommerceEntities db = new ECommerceEntities()) { try { PasswordManager PM = new PasswordManager(); t_Users US = new t_Users(); US.UserName = user.Username; US.Password = PM.Encrypt(user.Password); US.FirstName = user.FirstName; US.LastName = user.LastName; US.Email = user.Email; US.Gender = user.Gender; db.t_Users.Add(US); //db.SaveChanges(); var result = db.Database.ExecuteSqlCommand("exec upSaveUser @UserName, @Password, @Email, @FirstName, @Surname, @Gender", new SqlParameter("UserName", US.UserName), new SqlParameter("Password", US.Password), new SqlParameter("Email", US.Email), new SqlParameter("FirstName", US.FirstName), new SqlParameter("Surname", US.LastName), new SqlParameter("Gender", US.Gender)); //AddressModel AD = new AddressModel(); t_UsersAddress TAD = new t_UsersAddress(); TAD.AddressNumber = address.AddressNumber; TAD.AddressPostalCode = address.AddressPostalCode; TAD.AddressRoadName = address.AddressRoadName; TAD.AddressSuburb = address.AddressSuburb; TAD.UID = US.UID; TAD.AddressCity = address.AddressCity; db.t_UsersAddress.Add(TAD); //db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } } }
public ActionResult SignUp(UserModel USV, AddressModel AM) { try { if (ModelState.IsValid) { UserManagerFK UM = new UserManagerFK(); if (!UM.IsLoginNameExist(USV.Username) || !UM.IsEmailExist(USV.Email)) { UM.AddUserAccount(USV, AM); FormsAuthentication.SetAuthCookie(USV.FirstName, false); return RedirectToAction("Welcome", "Home"); } else { ModelState.AddModelError("", "Username already taken."); } } } catch (Exception ex) { throw new Exception(ex.Message); } return View(); }