コード例 #1
0
        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));
        }
コード例 #2
0
        public IActionResult Add()
        {
            Tenant tenant = new Tenant()
            {
                DateOfMovingIn = DateTime.Now
            };

            AddTenantModel model = new AddTenantModel()
            {
                Tenant     = tenant,
                Properties = _properties.GetAll()
            };

            return(View(model));
        }
コード例 #3
0
 public async Task <IActionResult> PostAsync([FromRoute] AddTenantModel data)
 {
     _tenantManagerActor.Tell(data);
     return(Accepted());
 }