示例#1
0
        public ServiceRequestBase ServiceRequestEdit(ServiceRequestEdit editedItem)
        {
            if (editedItem == null)
            {
                return(null);
            }

            var storedItem = ds.ServiceRequests.Find(editedItem.Id);

            if (storedItem == null)
            {
                return(null);
            }
            else
            {
                if (editedItem.RequestDate == null && storedItem.RequestDate == null)
                {
                    var today = DateTime.Now;
                    storedItem.RequestDate = today;
                }


                ds.Entry(storedItem).CurrentValues.SetValues(editedItem);
                ds.SaveChanges();

                return(Mapper.Map <ServiceRequestBase>(storedItem));
            }
        }
示例#2
0
        public IHttpActionResult Put(int id, [FromBody] ServiceRequestEdit editedItem)
        {
            if (editedItem == null)
            {
                return(BadRequest("Must send an entity body with the request"));
            }

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

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

                if (changedItem == null)
                {
                    // HTTP 400
                    return(BadRequest("Cannot edit the object"));
                }
                else
                {
                    // HTTP 200
                    return(Ok(changedItem));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }