Exemplo n.º 1
0
        public Response <Documentos> Post(InvoiceType Documento)
        {
            FactElectronica Fact = new FactElectronica();
            var             Res  = Fact.GeneraDocumentoElectronicoXML(Documento);

            if (Res.CodResponse == "0")
            {
                using (PosDbContext context = new PosDbContext())
                {
                    context.Add(Res.Data);
                    //Guardamos los cambios
                    context.SaveChanges();
                }
            }
            Res.Data.IdTramaNavigation.Documentos = null;
            return(Res);
        }
Exemplo n.º 2
0
        public Invoice InsertTransactionDetails(CartItem transactionDetails, List <SalesDetails> invoiceItemDetails)
        {
            var invoice = new Invoice()
            {
                EmployeeId = GetUserByUserId(1),
                DateOfSale = DateTime.Now,
                Discount   = Convert.ToDouble(transactionDetails.Discount.Split(" ")[0]),
                Vat        = Convert.ToDouble(transactionDetails.Vat.Split(" ")[0])
            };

            _posDbContext.Add <Invoice>(invoice);
            _posDbContext.SaveChanges();

            var invoiceItems = new List <ItemInSalesTransaction>();

            foreach (var invoiceItem in invoiceItemDetails)
            {
                var invoiceTransactionItem = new ItemInSalesTransaction()
                {
                    InvoiceReferenceNumber = invoice,
                    ProductReferenceId     = _posDbContext.Products.Where(p => p.ProductId == Convert.ToInt32(invoiceItem.ProductId)).SingleOrDefault(),
                    ConsumedQuantity       = Convert.ToInt32(invoiceItem.ConsumedQuantity),
                    TotalPrice             = Convert.ToDouble(invoiceItem.TotalPrice.Split(" ")[0])
                };

                invoiceItems.Add(invoiceTransactionItem);

                var product = GetPosStoreItemById(Convert.ToInt32(invoiceItem.ProductId));
                product.AvailableQuantity -= Convert.ToInt32(invoiceItem.ConsumedQuantity);
                _posDbContext.SaveChanges();
            }

            _posDbContext.SalesTransactions.AddRange(invoiceItems);
            _posDbContext.SaveChanges();

            return(invoice);
        }
Exemplo n.º 3
0
        public async Task <bool> CreateCategory(Category model)
        {
            Context.Add(model);

            return(await Context.SaveChangesAsync() == 1 ? true : false);
        }