Beispiel #1
0
        public async Task <IHttpActionResult> PostPurchaseOrderStatus(PurchaseOrderStatusVm vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = Task.Factory.StartNew(() =>
            {
                IUnitOfWork uow = new UnitOfWorkImp(new IRepositoryConnection[] { PurchaseOrderStatusRepository });
                var bo          = (BOPurchaseOrderStatus)vm.BOPurchaseOrderStatus(PurchaseOrderStatusRepository);
                uow.Create(bo);

                string err;
                if (!uow.Commit(out err))
                {
                    var resp = new HttpResponseMessage(HttpStatusCode.BadRequest)
                    {
                        Content = new StringContent(err)
                    };
                    throw new HttpResponseException(resp);
                }
                vm = new PurchaseOrderStatusVm(bo);
                return(true);
            });
            await result;

            return(CreatedAtRoute("DefaultApi", new { id = vm.İd }, vm));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> PutPurchaseOrderStatus(string id, PurchaseOrderStatusVm vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != vm.İd)
            {
                return(BadRequest());
            }

            var result = Task.Factory.StartNew(() => {
                IUnitOfWork uow = new UnitOfWorkImp(new IRepositoryConnection[] { PurchaseOrderStatusRepository });
                var bo          = (BOPurchaseOrderStatus)vm.BOPurchaseOrderStatus(PurchaseOrderStatusRepository);
                uow.Update(bo);

                string err;
                if (!uow.Commit(out err))
                {
                    var resp = new HttpResponseMessage(HttpStatusCode.BadRequest)
                    {
                        Content = new StringContent(err)
                    };
                    throw new HttpResponseException(resp);
                }
                return(true);
            });
            await result;

            if (!result.Result)
            {
                return(NotFound());
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }