Example #1
0
        public List <StockLevel> GetItemStockLevel(string itemCode)
        {
            {
                StringBuilder oSQL = new StringBuilder();
                oSQL.Append("select T0.WhsCode, T1.WhsName, OnHand, IsCommited, OnOrder, OnHand + OnOrder - IsCommited IsAvailable ");
                oSQL.Append("From OITW T0 inner join OWHS T1 on T0.WhsCode = T1.WhsCode ");
                oSQL.Append("where ItemCode = @itemCode and (OnHand > 0 or OnOrder > 0)");

                DbCommand dbCommand = this.dataBase.GetSqlStringCommand(oSQL.ToString());
                this.dataBase.AddInParameter(dbCommand, "itemCode", DbType.String, itemCode);

                List <StockLevel> itemStockLevel = new List <StockLevel>();

                using (this.reader = this.dataBase.ExecuteReader(dbCommand))
                {
                    while (this.reader.Read())
                    {
                        StockLevel stockWhs = new StockLevel();
                        stockWhs.WhsCode     = this.reader.IsDBNull(0) ? "" : this.reader.GetValue(0).ToString();
                        stockWhs.WhsName     = this.reader.IsDBNull(1) ? "" : this.reader.GetValue(1).ToString();
                        stockWhs.OnHand      = this.reader.IsDBNull(2) ? 0 : double.Parse(this.reader.GetValue(2).ToString());
                        stockWhs.IsCommited  = this.reader.IsDBNull(3) ? 0 : double.Parse(this.reader.GetValue(3).ToString());
                        stockWhs.OnOrder     = this.reader.IsDBNull(4) ? 0 : double.Parse(this.reader.GetValue(4).ToString());
                        stockWhs.IsAvailable = this.reader.IsDBNull(5) ? 0 : double.Parse(this.reader.GetValue(5).ToString());

                        itemStockLevel.Add(stockWhs);
                    }
                }
                return(itemStockLevel);
            }
        }
Example #2
0
        public ActionResult <StockLevel> Add(int productId, [FromBody] AddStocksCommand command)
        {
            var quantityInStock = _stockService.AddStock(productId, command.Amount);
            var stockLevel      = new StockLevel(quantityInStock);

            return(Ok(stockLevel));
        }
Example #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            StockLevel stockLevel = db.StockLevels.Find(id);

            db.StockLevels.Remove(stockLevel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult <StockLevel> Add(
            int productId,
            [FromBody] AddStocksCommand command,
            [FromServices] AddStocks useCase
            )
        {
            var product    = useCase.Handle(productId, command.Amount);
            var stockLevel = new StockLevel(product.QuantityInStock);

            return(Ok(stockLevel));
        }
Example #5
0
 public ActionResult Edit([Bind(Include = "ProductStockLevelID,StockID,ProductStockLevel")] StockLevel stockLevel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(stockLevel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StockID = new SelectList(db.Stocks, "StockID", "ProductName", stockLevel.StockID);
     return(View(stockLevel));
 }
Example #6
0
        public async Task <ActionResult <StockLevel> > AddAsync(
            int productId,
            [FromBody] AddStocks.Command command
            )
        {
            command.ProductId = productId;
            var product = await _mediator.Send(command);

            var stockLevel = new StockLevel(product.QuantityInStock);

            return(Ok(stockLevel));
        }
Example #7
0
        private static string ToStockLevelText(StockLevel stockLevel)
        {
            switch (stockLevel)
            {
            case StockLevel.Low: return("Only a few left");

            case StockLevel.SoldOutMoreNoRestock: return("Sold out");

            case StockLevel.SoldOutMoreSoon: return("Sold out, more comming soon!");

            default: return(string.Empty);
            }
        }
Example #8
0
        public async Task <ActionResult <StockLevel> > AddAsync(
            int productId,
            [FromBody] AddStocks.Command command,
            CancellationToken cancellationToken
            )
        {
            command.ProductId = productId;
            var quantityInStock = await _mediator.Send(command, cancellationToken);

            var stockLevel = new StockLevel(quantityInStock);

            return(Ok(stockLevel));
        }
Example #9
0
        // GET: StockLevels/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StockLevel stockLevel = db.StockLevels.Find(id);

            if (stockLevel == null)
            {
                return(HttpNotFound());
            }
            return(View(stockLevel));
        }
Example #10
0
        // GET: StockLevels/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StockLevel stockLevel = db.StockLevels.Find(id);

            if (stockLevel == null)
            {
                return(HttpNotFound());
            }
            ViewBag.StockID = new SelectList(db.Stocks, "StockID", "ProductName", stockLevel.StockID);
            return(View(stockLevel));
        }
Example #11
0
        public IEnumerable FilterByStock(StockLevel level)
        {
            switch (level)
            {
            case StockLevel.Low:
                return(_db.Products.Where(u => u.UnitsInStock < 50).Select(p => p.ProductName).ToList());

            case StockLevel.Normal:
                return(_db.Products.Where(u => u.UnitsInStock >= 50 && u.UnitsInStock <= 100).Select(p => p.ProductName).ToList());

            case StockLevel.Overstocked:
                return(_db.Products.Where(u => u.UnitsInStock > 100).Select(p => p.ProductName).ToList());

            default:
                return(null);
            }
        }
Example #12
0
 public ActionResult <StockLevel> Remove(int productId, [FromBody] RemoveStocksCommand command)
 {
     try
     {
         var quantityInStock = _stockService.RemoveStock(productId, command.Amount);
         var stockLevel      = new StockLevel(quantityInStock);
         return(Ok(stockLevel));
     }
     catch (NotEnoughStockException ex)
     {
         return(Conflict(new
         {
             ex.Message,
             ex.AmountToRemove,
             ex.QuantityInStock
         }));
     }
 }
Example #13
0
        public async Task <ActionResult <StockLevel> > RemoveAsync(
            int productId,
            [FromBody] RemoveStocks.Command command
            )
        {
            try
            {
                command.ProductId = productId;
                var product = await _mediator.Send(command);

                var stockLevel = new StockLevel(product.QuantityInStock);
                return(Ok(stockLevel));
            }
            catch (NotEnoughStockException ex)
            {
                return(Conflict(new
                {
                    ex.Message,
                    ex.AmountToRemove,
                    ex.QuantityInStock
                }));
            }
        }
 public IActionResult GetByStockLevel(StockLevel stockLevel, int pageSize = 25, int pageCount = 0)
 {
     return(Ok(_searchContext.GetByStockLevels(new[] { stockLevel }, pageCount, pageSize)));
 }
Example #15
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(ItemKey.ToString()).Append(" ").Append(ItemName.ToString()).Append(" ").Append(BarCodeNum.ToString()).Append(" ").Append(RetailPrice.ToString()).Append(" ").Append(ThresholdNum.ToString()).Append(" ").Append(StockLevel.ToString()).Append(" ").Append(SuppliersKey.ToString());
            return(sb.ToString());
        }