예제 #1
0
        public IHttpActionResult PostBoxItem(BoxItemsModel boxItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dbBoxItem = new BoxItem();

            dbBoxItem.Update(boxItem);

            _boxItemRepository.Add(dbBoxItem);
            _unitOfWork.Commit();

            boxItem.BoxItemId = dbBoxItem.BoxItemId;

            return(CreatedAtRoute("DefaultApi", new { id = boxItem.BoxItemId }, boxItem));
        }
예제 #2
0
        public IHttpActionResult PutBoxItem(int id, BoxItemsModel boxItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BoxItem dbBoxItem = _boxItemRepository.GetFirstOrDefault(b => b.Box.PawzeUser.UserName == User.Identity.Name && b.BoxItemId == id);

            if (id != boxItem.BoxItemId)
            {
                return(BadRequest());
            }

            dbBoxItem.Update(boxItem);

            _boxItemRepository.Update(dbBoxItem);

            try
            {
                _unitOfWork.Commit();
            }
            catch (Exception)
            {
                if (!BoxItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }