Exemple #1
0
        public IHttpActionResult GetHousingUnitsWithTenantsAvailable(int id)
        {
            var helper = new HousingUnitsHelper();
            var result = helper.GetHousingUnitsWithTenantsAvailable(id);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
Exemple #2
0
        public IHttpActionResult PutTenant(int id, [FromBody] TenantJsonPUT tenantJson)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tenantJson.TenantId)
            {
                return(BadRequest());
            }

            var housingUnitHelpper = new HousingUnitsHelper();
            var housingUnit        = housingUnitHelpper.GetHousingUnitsWithTenantsAvailable(tenantJson.HousingUnitId);

            if (housingUnit.Occupied < housingUnit.Capacity)
            {
                Tenant tenant = new Tenant
                {
                    tenantId      = tenantJson.TenantId,
                    contactId     = tenantJson.ContactId,
                    batchId       = tenantJson.BatchId,
                    housingUnitId = tenantJson.HousingUnitId,
                    genderId      = tenantJson.GenderId,
                    moveInDate    = tenantJson.MoveInDate,
                    hasMoved      = tenantJson.HasMoved,
                    hasKey        = tenantJson.HasKey
                };

                db.Entry(tenant).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TenantExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }