public ActionResult Register(RegisterModel model) { if (!model.Username.IsValidEmail()) { ModelState.AddModelError(string.Empty, "Invalid email address!"); return(View());//"Register"); } if (string.IsNullOrEmpty(model.Name)) { ModelState.AddModelError(string.Empty, "Please enter a name!"); return(View());//RedirectToAction("Register"); } if (string.IsNullOrEmpty(model.Password) || model.Password.Length < 6) { ModelState.AddModelError(string.Empty, "Password must be at least 6 charachters long!"); return(View());//RedirectToAction("Register"); } using (var db = new DealContext()) { var user = db.Users.FirstOrDefault( x => x.Username.ToLower() == model.Username.ToLower()); if (user != null) { ModelState.AddModelError(string.Empty, "User email already registerd!"); return(View());//RedirectToAction("Register"); } var u = new DfUser(); u.Username = model.Username; u.Password = model.Password; u.FirstName = model.Name; u.LastName = ""; u.UserEmail = model.Username; u.AuthCode = ""; u.Title = ""; u.CityId = 0; u.MobileNo = ""; u.AgeGroup = ""; u.UserGender = ""; u.DateCreated = DateTime.UtcNow; u.UserActive = true; db.Users.Add(u); db.SaveChanges(); FormsAuthentication.SetAuthCookie(model.Username, false); return(Redirect("/")); } }
/// <summary> Initializes the DB Context. </summary> /// <param name="context"> The DB Context to initialize. </param> public static void InitializeContext(DealContext context) { context.Database.EnsureCreated(); //* Use during development, then get rid of this in favor of Migrations if (context.Deal.Any()) { return; // DB has been seeded } var units = new Unit[] { new Unit { CustomerName = "Test, Bob", AppraiserName = "Appraiser, Jim", CustomerAddress = "100 Pigkicker Ln", ModelYear = 1999, VIN = "1M3P272K1XM001040" } }; var deals = new Deal[] { new Deal { } }; foreach (var deal in deals) { deal.UpdateAuditFields(1); } foreach (var unit in units) { unit.UpdateAuditFields(1); } var dealUnits = new DealUnit[] { new DealUnit { Deal = deals[0], Unit = units[0] } }; deals[0].DealUnits = dealUnits; context.Unit.AddRange(units); context.Deal.AddRange(deals); context.DealUnit.AddRange(dealUnits); context.SaveChanges(); }
public void Save() { _dbContext.SaveChanges(); }
public void Save() { dealContext.SaveChanges(); }