예제 #1
0
        // PUT api/Housing/5
        public async Task<IHttpActionResult> PutHousing(int id, Housing housing)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != housing.HousingID)
            {
                return BadRequest();
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HousingExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #2
0
        public int GenerateHousingLocationScore(Housing housing, List<Location> locations)
        {
            if ((housing == null) || (locations == null))
            {
                return 0;
            }

            var score = GenerateMutuallyPreferredLocationsScore(new List<Location> { housing.Location }, locations);

            return score;
        }
예제 #3
0
        public async Task<IHttpActionResult> PostHousing(Housing housing)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Housings.Add(housing);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = housing.HousingID }, housing);
        }