Example #1
0
        public HttpResponseMessage Put(int id, [FromBody] Category entity)
        {
            try
            {
                var entityOld = _service.GetById(id);
                if (entityOld == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Category with ID " + id.ToString() + " not found"));
                }
                else
                {
                    //Second approach - WORK !!
                    entityOld.CategoryName = entity.CategoryName;
                    entityOld.Description  = entity.Description;
                    entityOld.Picture      = entity.Picture;
                    entityOld.Products     = entity.Products;

                    _service.Save();

                    //First approach - Didn't work
                    //_service.Modify(entity);
                    return(Request.CreateResponse(HttpStatusCode.OK, entityOld));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }