Beispiel #1
0
        public async Task <ActionResult> AddProducts([FromBody] IAddProductsToBasket items)
        {
            items.ProductAmount = Math.Abs(items.ProductAmount);
            var username = User.Claims.FirstOrDefault(x => x.Type == "FullName").Value;

            var situation = await BasketService.AddProductsToBasket(items);

            if (situation == ProblemWithBasket.AllIsOkey)
            {
                var catalogFromDB = await DB.CatalogDB.Include(x => x.Warehouse).FirstOrDefaultAsync(x => x.Id == items.CatalogId);

                var catalogVM = new CatalogVM
                {
                    Id            = catalogFromDB.Id,
                    ProductPrice  = catalogFromDB.ProductPrice,
                    CurrentAmount = catalogFromDB.CurrentAmount,
                    MaximumAmount = catalogFromDB.MaximumAmount,
                    MinimumAmount = catalogFromDB.MinimumAmount,
                    WarehouseId   = catalogFromDB.WarehouseId,
                    Name          = catalogFromDB.Name.Name,
                };
                var log = new SimpleLogTable()
                {
                    Date        = DateTime.Now,
                    UserName    = username,
                    Action      = "Noņemts",
                    What        = items.Name,
                    Amount      = items.ProductAmount,
                    Manually    = "",
                    WarehouseId = catalogFromDB.WarehouseId.Value,
                    Where       = catalogFromDB.Warehouse.Name
                };
                await SimpleLogTableService.AddLog(log);

                return(Ok(catalogVM));
            }
            else
            {
                return(BadRequest(new { message = "Not enough products in catalog." }));
            }
        }