public ActionResult EditDetails(Customer model, bool Blank) { if (ModelState.IsValid) { //Update the logged-in user's record with all fields that have been updated, update the session message, and return to the user home page. var db = new JamesEntities(); var search = Session["Email"]; var toUpdate = db.Customer.Where(u => u.Email == search).FirstOrDefault(); if (model.FirstName != null) { toUpdate.FirstName = model.FirstName; } if (model.Surname != null) { toUpdate.Surname = model.Surname; } if (model.Password != null) { toUpdate.Password = Salt.Encode(model.Password, null); } if (model.ContactNumber != null) { toUpdate.ContactNumber = model.ContactNumber; } if (model.Email != null) { Session["Email"] = model.Email; toUpdate.Email = model.Email; } if (model.Address1 != null) { toUpdate.Address1 = model.Address1; } if (model.Address2 != null || Blank == true) { toUpdate.Address2 = model.Address2; } if (model.TownCity != null) { toUpdate.TownCity = model.TownCity; } if (model.County != null) { toUpdate.County = model.County; } if (model.Postcode != null) { toUpdate.Postcode = model.Postcode; } db.SaveChanges(); Session["Message"] = "Your details have been successfully updated."; return(RedirectToAction("Customer", "User")); } return(View(model)); }
public ActionResult CreateAccount(Customer model) { if (ModelState.IsValid) { //Creates a new record in the database, saves changes, and redirects to the starting page. var db = new JamesEntities(); db.Customer.Add(new Customer { FirstName = model.FirstName, Surname = model.Surname, Password = Salt.Encode(model.Password, null), ContactNumber = model.ContactNumber, Email = model.Email, Address1 = model.Address1, Address2 = model.Address2, TownCity = model.TownCity, County = model.County, Postcode = model.Postcode }); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(model)); }