Exemplo n.º 1
0
        public IActionResult OnGet(int?id)
        {
            var t = Request.Cookies["logon"];

            if (t == null)
            {
                return(RedirectToPage("../Accounts/Login"));
            }
            if (t == "false")
            {
                return(RedirectToPage("../Accounts/Login"));
            }

            if (id == null)
            {
                return(NotFound());
            }

            DetailInvoice = _service.GetDetailInvoice(id ?? default(int));

            if (DetailInvoice == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <IEnumerable <ResponseInvoice> > > Put(InvoiceFullDto invoiceFullDto)
        {
            var result = new ResponseInvoice();

            try
            {
                using (var tran = _facturaContexto.Database.BeginTransaction())
                {
                    try
                    {
                        var rs_invoice = await _facturaContexto.Invoices.Where(x => x.Id == invoiceFullDto.Id).FirstOrDefaultAsync();

                        if (rs_invoice == null)
                        {
                            return(BadRequest());
                        }
                        rs_invoice.ClientId       = invoiceFullDto.ClientId;
                        rs_invoice.NameShopkeeper = invoiceFullDto.NameShopkeeper;
                        rs_invoice.Date           = rs_invoice.Date;

                        _facturaContexto.Entry(rs_invoice).State = EntityState.Modified;
                        _facturaContexto.SaveChanges();

                        foreach (var item in invoiceFullDto.DetailInvoiceDto)
                        {
                            var detailp     = _facturaContexto.DetailInvoices.Find(item.ProductId);
                            var listProduct = new DetailInvoiceDto();
                            if (detailp == null)
                            {
                                return(BadRequest());
                            }
                            listProduct.ProductId  = item.ProductId;
                            listProduct.Precio_Pro = detailp.Precio_Pro;
                            listProduct.Cantidad   = item.Cantidad;
                            listProduct.Total      = detailp.Precio_Pro * item.Cantidad;

                            _facturaContexto.Entry(listProduct).State = EntityState.Modified;
                            _facturaContexto.SaveChanges();
                        }


                        await tran.CommitAsync();
                    }
                    catch (Exception)
                    {
                        await tran.RollbackAsync();

                        throw;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(Ok(result));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <IEnumerable <ResponseInvoice> > > GetAllInvoices()
        {
            //
            var resultInvoices = await _facturaContexto.Invoices.Include("DetailsNavigations").Include("DetailsNavigations.Product").Include("DetailsNavigations").Include("ClientNavigation").ToListAsync();

            var response_invoice = new List <ResponseInvoice>();

            if (resultInvoices == null)
            {
                return(BadRequest());
            }

            foreach (var invoice in resultInvoices)
            {
                var itemInvoce = new ResponseInvoice();
                itemInvoce.InvoiceId  = invoice.Id;
                itemInvoce.IdClient   = invoice.ClientNavigation.Id;
                itemInvoce.NameClient = invoice.ClientNavigation.Name;
                itemInvoce.Date       = invoice.Date;

                itemInvoce.DetailInvoice = new List <DetailInvoiceDto>();
                foreach (var detInvoice in invoice.DetailsNavigations)
                {
                    var itemDt = new DetailInvoiceDto();

                    itemDt.Product = new ProductDto
                    {
                        Id    = detInvoice.Product.Id,
                        Name  = detInvoice.Product.Name,
                        Price = detInvoice.Product.Price
                    };

                    itemDt.Precio_Pro = detInvoice.Precio_Pro;
                    itemDt.Id         = detInvoice.Id;
                    itemDt.ProductId  = detInvoice.ProductId;
                    itemInvoce.DetailInvoice.Add(itemDt);
                }



                response_invoice.Add(itemInvoce);
            }
            return(response_invoice);
        }