public bool AddStockManually(StockViewModel model)
        {
            bool res = false;

            switch (model.option)
            {
            case "Add":
                res = util.updateSingleQuantity(model.modelId, model.Quantity, model.store_id, "Add");
                break;

            case "Subtract":
                res = util.checkingQuantitySingleProduct(model.modelId, model.Quantity, model.store_id);
                if (!res)
                {
                    break;
                }
                res = util.updateSingleQuantity(model.modelId, model.Quantity, model.store_id, "Subtract");
                break;

            default:
                res = false;
                break;
            }
            return(res);
        }
Example #2
0
        public async Task <int> addPurchasing(PurchasingViewModel c, IUrlHelper Url)
        {
            bool res = false;
            // var price = context.BrandModel.Select(x => new { x.Price, x.modelId }).FirstOrDefault(x => x.modelId == c.modelId);
            Purchasing model = new Purchasing()
            {
                Date      = c.Date,
                Quantity  = c.Quantity,
                Amount    = c.Amount,
                modelId   = c.modelId,
                vendor_id = c.vendor_id,
                store_id  = c.store_id,
                takenBy   = c.takenBy,
            };

            context.Purchasings.Add(model);
            context.SaveChanges();
            res = util.updateSingleQuantity(c.modelId, c.Quantity, c.store_id, "Add");
            if (res == false)
            {
                return(0);
            }
            string StoreName = util.GetAllStores().FirstOrDefault(x => x.store_id == c.store_id).StoreName;
            var    users     = UserManager.Users.Where(x => x.store_id == c.store_id).ToList();

            NotificationsViewModel n = new NotificationsViewModel();

            n.heading = "Purchasing #" + model.purchase_id;
            n.Text    = "Items Purchased By " + c.takenBy;
            n.Url     = Url.Action("Details", "Purchasing", new { id = model.purchase_id });
            n.read    = false;
            n.When    = DateTime.Now;
            await _hubContext.Clients.Groups(StoreName).SendAsync("RecieveNotification", n);

            foreach (var em in users)
            {
                n.UserId = em.Id;
                await util.AddNotification(n);
            }
            context.SaveChanges();
            return(model.purchase_id);
        }