Esempio n. 1
0
        private List <ProviderModel> GetProveedorList()
        {
            var ProveedorList = db.Proveedor.ToList();
            var listClient    = MapperObject.CreateListProveedorModel(ProveedorList);

            return(listClient);
        }
Esempio n. 2
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;
                    }
                }
            }
        }
Esempio n. 3
0
        public List <CategoryModel> GetCategoryList()
        {
            var CategoryList = db.Category.ToList();
            var map          = MapperObject.CreateCategoryList(CategoryList);

            return(map);
        }
Esempio n. 4
0
        public List <TipoComprobantesModel> GetTypeInvoice()
        {
            var tipoComprobante = db.TipoComprobante.ToList();
            var listInvoice     = MapperObject.tipoComprobante(tipoComprobante);

            return(listInvoice);
        }
Esempio n. 5
0
        public void EditProduct(ProductModels product)
        {
            var id          = product.IdProducto;
            var productById = db.Product.Find(id);
            var productDb   = MapperObject.EditProductDb(product, productById);

            db.SaveChanges();
        }
Esempio n. 6
0
        public List <InvoiceDetailModel> GetDetailInvoice(Guid?IdComprobante)
        {
            var invoiceDetalle = db.GetInvoiceDetail(IdComprobante).ToList();
            var listInvoice    = MapperObject.CreateListDetailInvoiceModel(invoiceDetalle);


            return(listInvoice);
        }
Esempio n. 7
0
        public List <ClienteModel> GetClient()
        {
            lock (obj)
            {
                var clienteList = db.Cliente.ToList();
                var listClient  = MapperObject.CreateListClientModel(clienteList);

                return(listClient);
            }
        }
Esempio n. 8
0
        public List <ProductModels> MapProduct()
        {
            lock (obj)
            {
                var productList  = db.Product.ToList();
                var category     = db.Category.ToList();
                var subcategoria = db.SubCategory.ToList();

                return(MapperObject.CreateProductList(productList, category, subcategoria));
            }
        }
Esempio n. 9
0
        public List <ClienteModel> ObtenerCliente(int?page, int?limit, string sortBy, string direction, string searchString, out int total)
        {
            var clienteList = db.Cliente.ToList();
            var listClient  = Factory.Factory.ListClienteModels();

            //Edit Product Selected
            foreach (var item in clienteList)
            {
                var productList = Factory.Factory.CreateListProductdb();
                var pc          = db.IdClienteIdProducto.Where(x => x.IdCliente == item.IdCliente).ToList();

                foreach (var itemproduct in pc)
                {
                    var product = db.Product.Where(x => x.IdProducto == itemproduct.IdProducto).First();
                    productList.Add(product);
                }

                var map = MapperObject.CreateClienteProductModel(item, productList);
                listClient.Add(map);
            }

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                listClient = listClient.Where(p => (p.Nombre.ToUpper().StartsWith(searchString.ToUpper()) || p.Nombre.ToUpper().EndsWith(searchString.ToUpper())) ||
                                              (p.Codigo.ToUpper().StartsWith(searchString.ToUpper()) || p.Codigo.ToUpper().EndsWith(searchString.ToUpper())) ||
                                              (p.Apellido.ToUpper().StartsWith(searchString.ToUpper()) || p.Apellido.ToUpper().EndsWith(searchString.ToUpper()))).ToList();
            }

            total = clienteList.Count();
            var clienteQueryable = listClient.AsQueryable();

            if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
            {
                if (direction.Trim().ToLower() == "asc")
                {
                    clienteQueryable = SortHelper.OrderBy(clienteQueryable, sortBy);
                }
                else
                {
                    clienteQueryable = SortHelper.OrderByDescending(clienteQueryable, sortBy);
                }
            }

            if (page.HasValue && limit.HasValue)
            {
                int start = (page.Value - 1) * limit.Value;
                clienteQueryable = clienteQueryable.Skip(start).Take(limit.Value);
            }

            return(clienteQueryable.ToList());
        }
Esempio n. 10
0
        public virtual ProductModels GetProductById(Guid id)
        {
            var productById = db.Product.Find(id);
            var productMap  = MapperObject.CreateProductModel(productById);

            if (productMap.kg != null)
            {
                productMap.kg = Math.Round(productMap.kg.Value, 2);
            }

            productMap.Category    = GetCategoryList();
            productMap.SubCategory = GetSubCategoryList();
            return(productMap);
        }
Esempio n. 11
0
        public void CreateProduct(ProductModels product)
        {
            try
            {
                var productDb = MapperObject.CreateProductDb(product);
                db.Product.Add(productDb);

                db.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 12
0
        public List <InvoiceModel> GetInvoice(DateTime?dateFrom, DateTime?dateTo, string idClient, string idTypeVoucher)
        {
            if (dateFrom == null && dateTo == null && idClient == null)
            {
                dateFrom = DateTime.Now.AddDays(-7);
                dateTo   = DateTime.Now.Date;
            }

            var typeVocher = Convert.ToInt16(idTypeVoucher);

            var invoice     = db.GetInvoice(dateFrom, dateTo, typeVocher).ToList();
            var listInvoice = MapperObject.CreateListInvoiceModel(invoice);

            return(listInvoice);
        }
Esempio n. 13
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());
                    }
                }
            }
        }
Esempio n. 14
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());
                    }
                }
            }
        }
Esempio n. 15
0
        public List <ProductModels> GetProduct(int?page, int?limit, string sortBy, string direction, string searchString, out int total)
        {
            var productList      = db.Product.ToList();
            var categoriaList    = db.Category.ToList();
            var subCategoriaList = db.SubCategory.ToList();
            var tamanoList       = db.TamanoMascota.ToList();

            var product = MapperObject.CreateProductList(productList, categoriaList, subCategoriaList, tamanoList);

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                product = product.Where(p => p.Descripcion1.Contains(searchString) || p.Codigo.ToString().Contains(searchString)).ToList();
            }

            total = product.Count();

            var productQueryable = product.AsQueryable();

            if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
            {
                if (direction.Trim().ToLower() == "asc")
                {
                    productQueryable = SortHelper.OrderBy(productQueryable, sortBy);
                }
                else
                {
                    productQueryable = SortHelper.OrderByDescending(productQueryable, sortBy);
                }
            }

            if (page.HasValue && limit.HasValue)
            {
                int start = (page.Value - 1) * limit.Value;
                productQueryable = productQueryable.Skip(start).Take(limit.Value);
            }

            return(productQueryable.ToList());
        }
Esempio n. 16
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());
                    }
                }
            }
        }
Esempio n. 17
0
        public List <TamanoMascotaModel> GetTamañoMascota()
        {
            var tamañoMascota = db.TamanoMascota.ToList();

            return(MapperObject.CreateTamañoMascotaList(tamañoMascota));
        }
Esempio n. 18
0
        public List <TipoAnimalModel> GetTipoAnimal()
        {
            var tipoAnimal = db.TipoAnimal.ToList();

            return(MapperObject.CreateTipoAnimalList(tipoAnimal));
        }
Esempio n. 19
0
        public List <SubCategoryModel> GetSubCategory()
        {
            var subCategory = db.SubCategory.ToList();

            return(MapperObject.CreateSubCategoryList(subCategory));
        }
Esempio n. 20
0
        public List <CategoryModel> GetCategory()
        {
            var category = db.Category.ToList();

            return(MapperObject.CreateCategoryList(category));
        }
Esempio n. 21
0
        /// <summary>
        /// Map the source from a destination.
        /// </summary>
        /// <typeparam name="TSource">Source mapping.</typeparam>
        /// <param name="TDestination">Destination mapping.</param>
        /// <returns>A TDestination object.</returns>
        public TDestination map <TDestination>(object TSource)
        {
            var destination = MapperObject.Map <TDestination>(TSource);

            return(destination);
        }