コード例 #1
0
 public void Update(PropertyModel property)
 {
     Name = property.Name;
     Address1 = property.Address1;
     Address2 = property.Address2;
     City = property.City;
     State = property.State;
     Zip = property.Zip;
 }
コード例 #2
0
        public IHttpActionResult PostProperty(PropertyModel property)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbProperty = new Property();

            dbProperty.Update(property);

            db.Properties.Add(dbProperty);
            db.SaveChanges();

            property = Mapper.Map<PropertyModel>(dbProperty);

            return CreatedAtRoute("DefaultApi", new { id = property.PropertyId }, property);
        }
コード例 #3
0
        public IHttpActionResult PutProperty(int id, PropertyModel property)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != property.PropertyId)
            {
                return BadRequest();
            }

            var dbProperty = db.Properties.Find(id);

            dbProperty.Update(property);

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }