コード例 #1
0
        public async Task <IHttpActionResult> Post(StateProvince item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            item.ObjectState = ObjectState.Added;
            _service.Insert(item);

            try
            {
                await _unitOfWorkAsync.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ItemExists(item.StateProvinceID))
                {
                    return(Conflict());
                }
                throw;
            }

            return(Created(item));
        }