Exemplo n.º 1
0
        public async Task <IHttpActionResult> Deleteİnvoices(string id)
        {
            var result = Task.Factory.StartNew(() =>
            {
                IUnitOfWork uow = new UnitOfWorkImp(new IRepositoryConnection[] { İnvoicesRepository });
                var bo          = new BOInvoices();
                bo.Repository   = İnvoicesRepository;
                bo.Init(id);

                uow.Delete(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(Ok(result.Result));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> Postİnvoices(İnvoicesVm vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = Task.Factory.StartNew(() =>
            {
                IUnitOfWork uow = new UnitOfWorkImp(new IRepositoryConnection[] { İnvoicesRepository });
                var bo          = (BOInvoices)vm.BOİnvoices(İnvoicesRepository);
                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 İnvoicesVm(bo);
                return(true);
            });
            await result;

            return(CreatedAtRoute("DefaultApi", new { id = vm.İd }, vm));
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> Putİnvoices(string id, İnvoicesVm vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            var result = Task.Factory.StartNew(() => {
                IUnitOfWork uow = new UnitOfWorkImp(new IRepositoryConnection[] { İnvoicesRepository });
                var bo          = (BOInvoices)vm.BOİnvoices(İnvoicesRepository);
                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));
        }