Example #1
0
        public void SaveProduct(ProductModels product)
        {
            using (var context = new AnimaliaPetShopEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var productDb = MapperObject.CreateProductDb(product);

                        //AddNewProduct
                        AddProduct(productDb);

                        context.SaveChanges();

                        dbContextTransaction.Commit();
                    }
                    catch (Exception exepction)
                    {
                        dbContextTransaction.Rollback();
                        throw exepction;
                    }
                }
            }
        }
Example #2
0
        public static List <FormaDePago> GetFormaPagoLoadOrder()
        {
            db = Factory.Factory.CreateContextDataBase();
            var formaDePago = db.FormaDePago.Where(x => x.IdFormaDePago > 2).ToList();

            return(formaDePago);
        }
        public string Save(string proveedor, string date, string fechaPago, int formaDePago, string[] precioCosto, int[] cantidad, Guid[] idProducto, string[] precioVenta)
        {
            var listProveedor = GetProveedor();
            var idProveedor   = listProveedor.Where(x => x.RazonSocial == proveedor);

            using (var context = new AnimaliaPetShopEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var message = string.Empty;
                        db = Factory.Factory.CreateContextDataBase();

                        var head = SaveHead(idProveedor.First().IdProveedor, date, formaDePago, fechaPago, db);

                        SaveProductChange(precioCosto, cantidad, idProducto, precioVenta);

                        for (int i = 0; i < idProducto.Length; i++)
                        {
                            var detalleComprobante = new DetalleComprobante();
                            detalleComprobante.IdComprobante        = head.IdComprobante;
                            detalleComprobante.IdDetalleComprobante = Guid.NewGuid();
                            detalleComprobante.IdProducto           = idProducto[i];
                            detalleComprobante.PrecioCosto          = Convert.ToDecimal(precioCosto[i]);
                            detalleComprobante.PrecioVenta          = Convert.ToDecimal(precioVenta[i]);
                            detalleComprobante.Cantidad             = Convert.ToDecimal(cantidad[i]);

                            db.DetalleComprobante.Add(detalleComprobante);
                        }

                        db.SaveChanges();
                        dbContextTransaction.Commit();
                        return(message = "EL comprobante fue guardado exitosamente");
                    }
                    catch (Exception e)
                    {
                        throw new Exception(e.Message.ToString());
                    }
                }
            }
        }
Example #4
0
        public void GuardarCliente(ClienteModel clienteModel)
        {
            using (var context = new AnimaliaPetShopEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        db = Factory.Factory.CreateContextDataBase();


                        clienteModel.FechaCompra        = DateTime.Parse(clienteModel.FechaCompra1).Date;
                        clienteModel.FechaProximaCompra = DateTime.Parse(clienteModel.FechaCompra2).Date;

                        var clienteDb = MapperObject.CreateClienteDb(clienteModel);

                        if (clienteDb.IdCliente == null || clienteDb.IdCliente == Guid.Empty)
                        {
                            clienteDb.IdCliente = Guid.NewGuid();

                            db.Cliente.Add(clienteDb);
                            SaveProductsId(clienteModel, clienteDb.IdCliente);

                            db.SaveChanges();
                            dbContextTransaction.Commit();
                        }
                        else
                        {
                            SaveProductsId(clienteModel, clienteDb.IdCliente);
                            db.Cliente.Attach(clienteDb);
                            db.Entry(clienteDb).State = EntityState.Modified;
                            db.SaveChanges();
                            dbContextTransaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception(e.Message.ToString());
                    }
                }
            }
        }
Example #5
0
        public async Task <List <VentaDiariaMesModel> > GetVentasDiaria()
        {
            try
            {
                db = Factory.Factory.CreateContextDataBase();

                await Task.Delay(1000);

                var dia = db.VentaDiariaMes().ToList();

                var vtaModel = Factory.ReportFactory.CreateListventaDiariaModel();

                foreach (var item in dia)
                {
                    var venta = Factory.ReportFactory.CreateventaDiariaModel();
                    venta.Dia            = (item.dia != null) ? item.dia : 0;
                    venta.DescripcionDia = (item.Descripcion != null) ? item.Descripcion : string.Empty;

                    vtaModel.Add(venta);
                }

                int cant = dia.Count();

                if (cant > 0)
                {
                    vtaModel[cant - 1].TotalDia = 0;
                    foreach (var item in dia)
                    {
                        vtaModel[cant - 1].TotalDia += item.dia;
                    }
                }


                return(vtaModel);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            // using Object Context (EF4.0)
        }
Example #6
0
        public void SaveProvider(ProviderModel providerModel)
        {
            using (var context = new AnimaliaPetShopEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        db = Factory.Factory.CreateContextDataBase();

                        providerModel.Fecha = DateTime.Now;

                        var providerDb = MapperObject.CreateProviderDb(providerModel);

                        if (providerDb.IdProveedor == null || providerDb.IdProveedor == Guid.Empty)
                        {
                            providerDb.IdProveedor = Guid.NewGuid();

                            db.Proveedor.Add(providerDb);
                            SaveProductsId(providerModel, providerDb.IdProveedor);

                            db.SaveChanges();
                            dbContextTransaction.Commit();
                        }
                        else
                        {
                            SaveProductsId(providerModel, providerDb.IdProveedor);
                            db.Proveedor.Attach(providerDb);
                            db.Entry(providerDb).State = EntityState.Modified;
                            db.SaveChanges();
                            dbContextTransaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception(e.Message.ToString());
                    }
                }
            }
        }
Example #7
0
        public void SaveProductToLoose(Guid?idBug, Guid?idLoose, string precioCosto, string precioVenta)
        {
            using (var context = new AnimaliaPetShopEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        Product productBug    = db.Product.Find(idBug);
                        Product productLoose  = db.Product.Find(idLoose);
                        var     totalQuantity = productLoose.TotalKg + productBug.Kg;


                        var precioCostoNew = ((Math.Round(productLoose.TotalKg.Value, 2) * Math.Round(productLoose.PrecioCosto.Value, 2)) + ((Math.Round(productBug.Kg.Value, 2)) * (Convert.ToDecimal(precioCosto)))) / Math.Round(totalQuantity.Value, 2);
                        productLoose.PrecioCosto = precioCostoNew;
                        productLoose.PrecioVenta = Convert.ToDecimal(precioVenta);
                        productLoose.TotalKg     = productLoose.TotalKg + productBug.Kg;

                        productBug.TotalKg  = productBug.TotalKg - productBug.Kg;
                        productBug.Cantidad = productBug.Cantidad - 1;


                        db.SaveChanges();

                        dbContextTransaction.Commit();
                    }
                    catch (Exception exepction)
                    {
                        dbContextTransaction.Rollback();
                        throw exepction;
                    }


                    // producto.First().PrecioCosto = Convert.ToDecimal((Convert.ToDecimal(producto.First().Cantidad) * producto.First().PrecioCosto) + (Convert.ToDecimal(cantidad[i]) * Convert.ToDecimal(precioCosto[i]))) / cantidadTotal;
                }
            }
        }
Example #8
0
        public async Task <List <VentaDiariaMesModel> > GetVentasMes()
        {
            try
            {
                db = Factory.Factory.CreateContextDataBase();
                var mes = db.VentaMes().ToList();

                var vtaModel = Factory.ReportFactory.CreateListventaDiariaModel();


                foreach (var item in mes)
                {
                    var venta = Factory.ReportFactory.CreateventaDiariaModel();
                    venta.Mes            = (item.Mes != null) ? item.Mes : 0;
                    venta.DescripcionMes = (item.Descripcion != null) ? item.Descripcion : string.Empty;
                    vtaModel.Add(venta);
                }

                int cant = mes.Count();

                if (cant > 0)
                {
                    vtaModel[cant - 1].TotalMes = 0;
                    foreach (var item in mes)
                    {
                        vtaModel[cant - 1].TotalMes += item.Mes;
                    }
                }

                return(vtaModel);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #9
0
 public HomeManager()
 {
     db = Factory.Factory.CreateContextDataBase();
 }
Example #10
0
 public VoucheHeadManager()
 {
     db = Factory.Factory.CreateContextDataBase();
 }
Example #11
0
 public InvoiceManager()
 {
     db = Factory.Factory.CreateContextDataBase();
 }
 public ListProductManager()
 {
     db = Factory.Factory.CreateContextDataBase();
 }
Example #13
0
        public Comprobante SaveHead(Guid idProveedor, string date, int formaDePago, string fechaPago, AnimaliaPetShopEntities db)
        {
            var head = new Comprobante();

            head.IdComprobante     = Guid.NewGuid();
            head.IdProveedor       = idProveedor;
            head.IdTipoComprobante = (int)Enumeration.TipoComprobante.NotaPedido;
            head.IdFormaDePago     = formaDePago;
            head.FechaPago         = Convert.ToDateTime(fechaPago);
            head.Fecha             = Convert.ToDateTime(date);

            db.Comprobante.Add(head);
            return(head);
        }
Example #14
0
 public ReportVentas()
 {
     db = Factory.Factory.CreateContextDataBase();
 }
Example #15
0
        public bool SaveVoucher(List <DetailGrid> detailGridTemp, VoucherHeadModel head)
        {
            var detail  = MappModels(detailGridTemp);
            var message = string.Empty;

            using (var context = new AnimaliaPetShopEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        db = Factory.Factory.CreateContextDataBase();
                        decimal total = 0;

                        total = detail.Sum(item => item.Subtotal);

                        head.Total = total;
                        var headDb          = MapperObject.CreateVoucherHeadDb(head);
                        var voucherDetailDb = MapperObject.CreateVoucherDetailDb(detail);

                        headDb.IdComprobante = Guid.NewGuid();
                        db.Comprobante.Add(headDb);

                        foreach (var item in voucherDetailDb)
                        {
                            item.IdDetalleComprobante = Guid.NewGuid();
                            item.IdComprobante        = headDb.IdComprobante;
                            var product = db.Product.Find(item.IdProducto);

                            if (verifyQuantyty(item, product))
                            {
                                if (product.IdCategory != (int)Enumeration.Category.Accesorios)
                                {
                                    if (product.IdSubCategory != (int)Enumeration.Subcategory.Suelto)
                                    {
                                        product.Cantidad = product.Cantidad - item.Cantidad;
                                        product.TotalKg  = product.TotalKg - (item.Cantidad * product.Kg);
                                    }
                                    else
                                    {
                                        product.TotalKg = product.TotalKg - item.Cantidad;
                                    }
                                }
                                else
                                {
                                    product.Cantidad = product.Cantidad - item.Cantidad;
                                }
                            }
                            else
                            {
                                return(false);
                            }

                            db.DetalleComprobante.Add(item);
                        }

                        db.SaveChanges();
                        dbContextTransaction.Commit();
                        return(true);
                    }
                    catch (Exception e)
                    {
                        throw new Exception(e.Message.ToString());
                    }
                }
            }
        }
Example #16
0
 public ProviderManager()
 {
     db = Factory.Factory.CreateContextDataBase();
 }