Пример #1
0
        public ActionResult SubInv_Create([DataSourceRequest] DataSourceRequest request, SubInvModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                SubInventory subinv = Mappings.ToEntity(model);
                subinv.ObjectState = ObjectState.Added;
                subinv.CreatedBy   = subinv.ModifiedBy = "I-ALI";
                subinv.CreatedDate = subinv.ModifiedDate = DateTime.Now;

                _subInventoryService.Insert(subinv);

                try
                {
                    _unitOfWorkAsync.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ItemExists(subinv.SubInvCode))
                    {
                        throw new Exception("Item already exists.");
                    }

                    throw;
                }
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
Пример #2
0
        // POST: odata/subinventory
        public async Task <IHttpActionResult> Post(SubInventory subinventory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            subinventory.ObjectState = ObjectState.Added;
            _subInventoryService.Insert(subinventory);

            try
            {
                await _unitOfWorkAsync.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemExists(subinventory.SubInvCode))
                {
                    return(Conflict());
                }

                throw;
            }

            return(Created(subinventory));
        }