public IHttpActionResult Put(int id, [FromBody] ApartmentEdit editedItem)
        {
            if (editedItem == null)
            {
                return(BadRequest("Must send an entity body with the request"));
            }

            if (id != editedItem.ApartmentNumber)
            {
                return(BadRequest("Invalid data in the entity body"));
            }

            if (ModelState.IsValid)
            {
                var changedItem = m.ApartmentEdit(editedItem);

                if (changedItem == null)
                {
                    // HTTP 400
                    return(BadRequest("Cannot edit the object"));
                }
                else
                {
                    // HTTP 200
                    return(Ok(changedItem));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Esempio n. 2
0
        public ApartmentWithUnit ApartmentEdit(ApartmentEdit editedItem)
        {
            if (editedItem == null)
            {
                return(null);
            }
            var storedItem = ds.Apartments.SingleOrDefault(e => e.ApartmentNumber == editedItem.ApartmentNumber);

            if (storedItem == null)
            {
                return(null);
            }
            else
            {
                ds.Entry(storedItem).CurrentValues.SetValues(editedItem);
                ds.SaveChanges();

                return(Mapper.Map <ApartmentWithUnit>(storedItem));
            }
        }