コード例 #1
0
        public Guid?AddNewInventory(InventoryViewModel inventoryViewModel)
        {
            var car = _mapper.Map <Car>(inventoryViewModel);

            car = NullifyDependantEntities(car);
            car = ManageCarAttributes(inventoryViewModel, car);

            Guid?newCarId = _carRepository.AddNewCar(car);

            if (newCarId == null)
            {
                return(null);
            }

            inventoryViewModel.CarId = (Guid)newCarId;

            var inventory = _mapper.Map <Inventory>(inventoryViewModel);


            Guid?newInventoryId = _inventoryRepository.AddInventory(inventory);

            inventoryViewModel.Id = (Guid)newInventoryId;


            var repairDetails = _mapper.Map <Repair>(inventoryViewModel);

            repairDetails.CarId = (Guid)newCarId;

            _repairRepository.AddNewRepair(repairDetails);

            return(newInventoryId);
        }
コード例 #2
0
 // POST api/inventory
 public IHttpActionResult Post([FromBody] Inventory inventory)
 {
     try
     {
         _inventoryRepository.AddInventory(inventory);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.InternalServerError, "Unable to add record in inventory."));
     }
 }
コード例 #3
0
        public async Task <IActionResult> Post([FromBody] InventoryViewModel inventory)
        {
            if (ModelState.IsValid)
            {
                var newInventory = Mapper.Map <Inventory>(inventory);
                _repository.AddInventory(newInventory);

                if (await _repository.SaveChangesAsync())
                {
                    return(Created($"api/Item/{inventory.Name}", Mapper.Map <InventoryViewModel>(newInventory)));
                }

                //return Ok();
            }

            return(BadRequest("Failed to save changes"));
        }
コード例 #4
0
 public void AddInventory(Inventory newInventory)
 {
     _repo.AddInventory(newInventory);
 }
コード例 #5
0
 public long AddInventory(InventoryAddModel model)
 {
     return(_inventoryRepository.AddInventory(model));
 }
コード例 #6
0
        /// <summary>
        /// Upload the data into the databases.
        /// </summary>
        public void UploadData()
        {
            List <long> commitTimes = new List <long>();
            var         readTimer   = new Stopwatch();

            readTimer.Start();
            var vr = new CsvHelper.CsvReader(File.OpenText(Path.Combine(dataPath, "vendor-master.csv")));

            vr.Configuration.HasHeaderRecord = false;
            vr.Configuration.RegisterClassMap <VendorMap>();
            vr.Configuration.DetectColumnCountChanges = true;
            var ir = new CsvHelper.CsvReader(File.OpenText(Path.Combine(dataPath, "inv-master.csv")));

            ir.Configuration.HasHeaderRecord          = false;
            ir.Configuration.DetectColumnCountChanges = true;

            int       z          = 0;
            var       writeTimer = new Stopwatch();
            Vendor    vendor;
            Inventory inv;

            while (vr.Read())
            {
                writeTimer.Start();
                int y = z + 5;
                vendor = vr.GetRecord <Vendor>();
                vendorRepo.AddVendor(vendor);

                for (int x = z; x < y; x++)
                {
                    if (ir.Read())
                    {
                        inv = new Inventory(vendor.VendorName)
                        {
                            Category = ir.GetField(2),
                            Name     = ir.GetField(3),
                            Price    = ir.GetField <double>(0),
                            Quantity = ir.GetField <int>(1)
                        };
                        invRepo.AddInventory(ir.GetField(5), inv);
                    }
                    else
                    {
                        log.LogCritical($"{DateTime.Now}\tno more inventory");
                    }
                }
                z = y;
                writeTimer.Stop();
                commitTimes.Add(writeTimer.ElapsedTicks);
                writeTimer.Reset();
            }

            vendorRepo.Save();
            readTimer.Stop();
            log.LogInformation("-----------------------------");
            log.LogInformation("");
            log.LogInformation("");
            log.LogInformation($"Read of CSV files took {readTimer.Elapsed.Minutes}:{readTimer.Elapsed.Seconds}.{readTimer.Elapsed.Milliseconds}.");
            readTimer.Reset();
            readTimer.Start();
            vendorRepo.Save();
            invRepo.Save();
            readTimer.Stop();
            log.LogInformation($"syncing databases took {readTimer.ElapsedMilliseconds} milliseconds.");
            log.LogInformation("");
            log.LogInformation($" Average write for each iteration (1 vendor, 5 inventory) averaged {commitTimes.Average()} ticks. Min: {commitTimes.Min()} Max: {commitTimes.Max()}");
        }
コード例 #7
0
        public ActionResult AddNewProduct(ProductRequestModel product, HttpPostedFileBase image)
        {
            var path = Request.MapPath("~/Content/" + product.categoryId);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            var filePath = Path.Combine(path, Path.GetFileName(image.FileName));

            try
            {
                image.SaveAs(filePath);
            }
            catch
            {
                throw new Exception();
            }
            string  imgPath  = filePath.Substring(path.IndexOf("\\Content"));
            string  RealPath = imgPath.Replace("\\", "/");
            Product p        = new Product()
            {
                CategoryId     = product.categoryId,
                IsOnSale       = false,
                ProductionDate = product.productionTime,
                ProviderId     = product.provider,
                Url            = RealPath,
                KeepDate       = product.keepTime,
                Price          = product.price,
                ProductName    = product.productName
            };
            long productId = _productRepository.AddProduct(p);

            //Add to ProductInFactory table
            ProductInFactory productInFactory = new ProductInFactory()
            {
                Amount = product.productCount,
                InDate = DateTime.UtcNow,
                Price  = Convert.ToString(p.Price),
            };
            long productInFactoryId = _inventoryRepository.AddProductInFactory(productInFactory);

            //Add to Inventory table
            Inventory inventory = new Inventory()
            {
                Amount      = product.productCount,
                ProductId   = productId,
                WarehouseId = product.warehouse,
            };
            long inventoryId = _inventoryRepository.AddInventory(inventory);


            //Add InventoryAction
            InventoryAction inventoryAction = new InventoryAction()
            {
                InventoryId        = inventoryId,
                ProductInFactoryId = productInFactoryId
            };

            _inventoryRepository.AddInventoryAction(inventoryAction);


            //Add to Discount table
            Discount discount = new Discount()
            {
                Discounts = Constants.DEFAULTDISCOUNT,
                IsUsed    = false,
                ProductId = productId,
                StartTime = DateTime.UtcNow,
                EndTime   = DateTime.UtcNow
            };

            _discountRepository.AddProductDiscount(discount);
            //InventoryProductListViewModel productViewModel = GetInventoryProducts(null,null);
            return(RedirectToAction("GetAllInventoryProduct", "Inventory"));
        }