private void UpdateStock(List <BillDetail> foods, List <BillDetail> toys, List <BillDetail> costumes) { CredentialModel credential = JsonConvert.DeserializeObject <CredentialModel>(HttpContext.Session.GetString(Constants.VM)); string token = credential.JwToken; //HTTP PUT FOOD foreach (var food in foods) { // get Current Inventory for ProductID FoodProduct stockFood = GetApiFoodProducts.GetFoodProducts().SingleOrDefault(p => p.ProductId == food.ProductId); // update stock amount stockFood.FoodAmount -= food.ProductAmount; // request update GetApiFoodProducts.UpdateStock(stockFood, token); } //HTTP PUT TOY foreach (var toy in toys) { // get Current Inventory for ProductID ToyProduct stock = GetApiToyProducts.GetToyProducts().SingleOrDefault(p => p.ProductId == toy.ProductId); // update stock amount stock.ToyAmount -= toy.ProductAmount; // request update GetApiToyProducts.UpdateStock(stock, token); } //HTTP PUT COSTUME foreach (var costume in costumes) { // get Size of billDetail string size = costume.NoteSize; // get Current Inventory for ProductID CostumeProduct stock = GetApiCostumeProducts.GetCostumeProducts().SingleOrDefault(p => p.ProductId == costume.ProductId && p.CostumeSize == costume.NoteSize); // update stock amount stock.CostumeAmountSize -= costume.ProductAmount; // request update GetApiCostumeProducts.UpdateStock(stock, token); } }
public IActionResult CancelBill(int billId) { //get credential CredentialModel credential = HttpContext.Session.GetObject <CredentialModel>(Constants.VM); //get token string token = credential.JwToken; // get bill and billdetail Bill bill = GetApiMyBills.GetBills(credential).SingleOrDefault(p => p.BillId == billId); List <BillDetailModel> billDetails = GetBills().SingleOrDefault(p => p.BillId == bill.BillId).BillDetail; // Update status for bill want to be canceled bill.IsCancel = true; UpdateBill(bill, credential); // update amount foreach (var detail in billDetails) { if (IsFood(detail.ProductId)) { FoodProduct food = GetApiFoodProducts.GetFoodProducts().SingleOrDefault(p => p.ProductId == detail.ProductId); food.FoodAmount += detail.Amount; GetApiFoodProducts.UpdateStock(food, token); } else if (IsToy(detail.ProductId)) { ToyProduct toy = GetApiToyProducts.GetToyProducts().SingleOrDefault(p => p.ProductId == detail.ProductId); toy.ToyAmount += detail.Amount; GetApiToyProducts.UpdateStock(toy, token); } else { CostumeProduct costume = GetApiCostumeProducts.GetCostumeProducts().SingleOrDefault(p => p.ProductId == detail.ProductId && p.CostumeSize == detail.NoteSize); costume.CostumeAmountSize += detail.Amount; GetApiCostumeProducts.UpdateStock(costume, token); } } return(RedirectToAction("Index")); }
public IActionResult SaveInventoryReceiveNote() { // get credential CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE)); //prepair data List <InventoryRecieveItem> inventoryRecieveItems = IRItems; InventoryReceiveNoteModel inventoryReceivingNote = new InventoryReceiveNoteModel() { InventoryReceivingDateReceiving = DateTime.Now, InventoryReceivingTotalPrice = inventoryRecieveItems.Sum(p => p.Total) }; // create inventory Receive Note InventoryReceivingNote createdReceivingNote = CreateInventoryReceiveNote(inventoryReceivingNote, credential.JwToken); // get list toy, food, costume List <InventoryReceivingNoteDetailForFood> noteDetailForFoods = inventoryRecieveItems .Where(p => IsFood(p.ProductId)) .Select(p => new InventoryReceivingNoteDetailForFood() { InventoryReceivingId = createdReceivingNote.InventoryReceivingId, FoodProductId = GetApiFoodProducts.GetFoodProducts() .SingleOrDefault(k => k.ProductId == p.ProductId).FoodId, FoodProductAmount = p.Amount, FoodProductPrice = p.Price }).ToList(); List <InventoryReceivingNoteDetailForToy> noteDetailForToys = inventoryRecieveItems .Where(p => IsToy(p.ProductId)) .Select(p => new InventoryReceivingNoteDetailForToy() { InventoryReceivingId = createdReceivingNote.InventoryReceivingId, ToyProductId = GetApiToyProducts.GetToyProducts() .SingleOrDefault(k => k.ProductId == p.ProductId).ToyId, ToyProductAmount = p.Amount, ToyProductPrice = p.Price }).ToList(); List <InventoryReceivingNoteDetailForCostume> noteDetailForCostumes = inventoryRecieveItems .Where(p => IsCostume(p.ProductId)) .Select(p => new InventoryReceivingNoteDetailForCostume() { InventoryReceivingId = createdReceivingNote.InventoryReceivingId, CostumeProductId = GetApiCostumeProducts.GetCostumeProducts() .SingleOrDefault(k => k.ProductId == p.ProductId && k.CostumeSize == p.Size).CostumeId, CostumeProductAmount = p.Amount, CostumeProductSize = p.Size, CostumeProductPrice = p.Price }).ToList(); // create IR food list foreach (var food in noteDetailForFoods) { //create GetApiInventoryReceivingNoteDetailForFoods.Post(food, credential.JwToken); //update amount for product FoodProduct foodProduct = GetApiFoodProducts.GetFoodProducts() .SingleOrDefault(p => p.FoodId == food.FoodProductId); foodProduct.FoodAmount += food.FoodProductAmount; GetApiFoodProducts.UpdateStock(foodProduct, credential.JwToken); } // create IR toy list foreach (var toy in noteDetailForToys) { GetApiInventoryReceiveNoteDetailForToys.Post(toy, credential.JwToken); //update amount for product ToyProduct toyProduct = GetApiToyProducts.GetToyProducts() .SingleOrDefault(p => p.ToyId == toy.ToyProductId); toy.ToyProductAmount += toy.ToyProductAmount; GetApiToyProducts.UpdateStock(toyProduct, credential.JwToken); } // create IR costume list foreach (var costume in noteDetailForCostumes) { GetApiInventoryReceiveNoteDetailForCostumes.Post(costume, credential.JwToken); //update amount for product CostumeProduct costumeProduct = GetApiCostumeProducts.GetCostumeProducts() .SingleOrDefault(p => p.CostumeId == costume.CostumeProductId && p.CostumeSize == costume.CostumeProductSize); costumeProduct.CostumeAmountSize += costume.CostumeProductAmount; GetApiCostumeProducts.UpdateStock(costumeProduct, credential.JwToken); } HttpContext.Session.Remove("inventoryRecieveItems"); return(Json(createdReceivingNote)); }