Beispiel #1
0
        public ActionResult AddProduct(ClassProduct a, Image imageModel, HttpPostedFileBase ImageFile)
        {
            ComputerShopEntities data = new ComputerShopEntities();
            InfoProduct          b    = new InfoProduct();

            b.Name          = a.Name;
            b.Price         = a.price;
            b.Description   = a.description;
            b.idProductType = a.idProduct;
            data.InfoProducts.Add(b);
            data.SaveChanges();
            imageModel.idProduct = b.Id;
            imageModel.Title     = b.Name;
            string fileName  = Path.GetFileNameWithoutExtension(ImageFile.FileName);
            string extension = Path.GetExtension(ImageFile.FileName);

            fileName             = fileName + DateTime.Now.ToString("yymmssfff") + extension;
            imageModel.ImagePath = fileName;
            fileName             = Path.Combine(Server.MapPath("~/img/"), fileName);
            ImageFile.SaveAs(fileName);
            using (ComputerShopEntities db = new ComputerShopEntities())
            {
                db.Images.Add(imageModel);
                db.SaveChanges();
                ViewBag.a = "Thêm sản phẩm thành cống";
            }
            ModelState.Clear();
            return(View());
        }
Beispiel #2
0
        //Hiển thị form thêm sản phẩm
        public async Task <IActionResult> AddProduct()
        {
            InfoProduct infoProduct = new InfoProduct();

            var ManufacturersContext = _context.Manufacturers.OrderBy(m => m.ManufacturerId).ToList();
            var DiscountsContext     = _context.Discounts.OrderBy(m => m.DiscountId);
            var RamContext           = _context.Rams.OrderBy(m => m.RamId);
            var RomContext           = _context.Roms.OrderBy(m => m.RomId);



            infoProduct.ManufacturerViewModel = ManufacturersContext.ToList();
            infoProduct.DiscountViewModel     = DiscountsContext.ToList();
            infoProduct.RamViewModel          = RamContext.ToList();
            infoProduct.RomViewModel          = RomContext.ToList();


            return(View(infoProduct));
        }
Beispiel #3
0
        public ActionResult Edit(ClassProduct a, Image imageModel, HttpPostedFileBase ImageFile)
        {
            ComputerShopEntities data = new ComputerShopEntities();
            var u = data.InfoProducts.Where(x => x.Id == a.id).FirstOrDefault();
            var y = data.Images.Where(k => k.idProduct == a.id).FirstOrDefault();

            if (u != null)
            {
                if (y != null)
                {
                    data.Images.Remove(y);
                }

                data.InfoProducts.Remove(u);
                data.SaveChanges();
            }
            InfoProduct b = new InfoProduct();

            b.Name          = a.Name;
            b.Price         = a.price;
            b.Description   = a.description;
            b.idProductType = a.idProduct;
            data.InfoProducts.Add(b);
            data.SaveChanges();
            imageModel.idProduct = b.Id;
            imageModel.Title     = b.Name;
            string fileName  = Path.GetFileNameWithoutExtension(ImageFile.FileName);
            string extension = Path.GetExtension(ImageFile.FileName);

            fileName             = fileName + DateTime.Now.ToString("yymmssfff") + extension;
            imageModel.ImagePath = fileName;
            fileName             = Path.Combine(Server.MapPath("~/img/"), fileName);
            ImageFile.SaveAs(fileName);
            using (ComputerShopEntities db = new ComputerShopEntities())
            {
                db.Images.Add(imageModel);
                db.SaveChanges();
                ViewBag.a = "Sửa thành công";
            }

            ModelState.Clear();
            return(View());
        }
Beispiel #4
0
        public void Supply(SupplyProductVM obj)
        {
            var product = _productService.All().FirstOrDefault(x => x.Title == obj.Name && x.ShopId == obj.ShopId);

            if (product == null)
            {
                var productForCopy = _productService.All().FirstOrDefault(x => x.Id == obj.ProductId);

                product = _productService.Create(new Product()
                {
                    Title         = productForCopy.Title,
                    Code          = productForCopy.Code,
                    Reserv        = productForCopy.Reserv,
                    BookingAmount = 0,
                    Cost          = productForCopy.Cost,
                    CategoryId    = productForCopy.CategoryId,
                    ShopId        = obj.ShopId,
                });
            }

            var supplyHistory = _supplyHistoryService.Create(new SupplyHistory());

            InfoProduct info;

            if (obj.SupplierId != 0)
            {
                info = new InfoProduct()
                {
                    Amount          = obj.Amount,
                    Date            = DateTime.Now.AddHours(3),
                    ProductId       = product.Id,
                    ShopId          = product.ShopId,
                    SupplierId      = obj.SupplierId,
                    Type            = InfoProductType.Supply,
                    SupplyHistoryId = supplyHistory.Id
                };

                var supplyProduct = new SupplyProduct()
                {
                    ProductId         = product.Id,
                    SupplierId        = obj.SupplierId,
                    TotalAmount       = obj.Amount,
                    RealizationAmount = obj.Realization == SupplyType.ForRealization ? obj.Amount : 0,
                    AdditionalCost    = obj.AdditionalCost / obj.Amount,
                    ProcurementCost   = obj.ProcurementCost / obj.Amount,
                    FinalCost         = (obj.ProcurementCost / obj.Amount) + (obj.AdditionalCost / obj.Amount),
                    StockAmount       = obj.Amount,
                    SupplyHistoryId   = supplyHistory.Id
                };

                _postgresContext.ProductOperations.Add(new ProductOperation(
                                                           product.Id,
                                                           obj.Amount,
                                                           DateTime.Now.AddHours(3),
                                                           obj.ProcurementCost / obj.Amount,
                                                           obj.Realization == SupplyType.ForRealization,
                                                           obj.SupplierId,
                                                           StorageType.Shop));
                _postgresContext.SaveChanges();

                _supplyProductService.Create(supplyProduct);

                if (obj.Realization == SupplyType.DeferredPayment)
                {
                    _deferredSupplyProductService.Create(new DeferredSupplyProduct()
                    {
                        Date            = obj.Date,
                        SupplyProductId = supplyProduct.Id
                    });
                }
            }
            else
            {
                var supply = _supplyProductService.Create(new SupplyProduct()
                {
                    ProductId         = product.Id,
                    TotalAmount       = obj.Amount,
                    RealizationAmount = obj.Realization == SupplyType.ForRealization ? obj.Amount : 0,
                    AdditionalCost    = obj.AdditionalCost / obj.Amount,
                    ProcurementCost   = obj.ProcurementCost / obj.Amount,
                    FinalCost         = (obj.ProcurementCost / obj.Amount) + (obj.AdditionalCost / obj.Amount),
                    StockAmount       = obj.Amount,
                    SupplyHistoryId   = supplyHistory.Id
                });

                info = new InfoProduct()
                {
                    Amount          = obj.Amount,
                    Date            = DateTime.Now.AddHours(3),
                    ProductId       = product.Id,
                    ShopId          = product.ShopId,
                    Type            = InfoProductType.Supply,
                    SupplyHistoryId = supplyHistory.Id,
                };
            }


            _infoProductService.Create(info);
        }
Beispiel #5
0
 private void CreateHistory(InfoProduct obj)
 {
     _infoProductService.Create(obj);
 }