public IActionResult Add(AddTenantModel model) { // The value gets set to null on redirect model.Properties = _properties.GetAll(); if (ModelState.IsValid) { if (_tenants.IsEmailTaken(model.Tenant.Email)) { ModelState.AddModelError("Tenant.Email", "This email is already taken."); return(View(model)); } if (model.Tenant.DateOfMovingIn > DateTime.Now) { ModelState.AddModelError("Tenant.DateOfMovingIn", "Date cannot be in the future."); return(View(model)); } Tenant newTenant = new Tenant() { FirstName = model.Tenant.FirstName, LastName = model.Tenant.LastName, Email = model.Tenant.Email, PhoneNumber = model.Tenant.PhoneNumber, DateOfMovingIn = model.Tenant.DateOfMovingIn }; _tenants.Add(newTenant, model.RentedPropertyId); return(RedirectToAction("All")); } return(View(model)); }