public static InventoryReceivingNote Post(InventoryReceiveNoteModel inventoryReceivingNote, string token)
        {
            using (var client = HelperClient.GetClient(token))
            {
                client.BaseAddress = new Uri(Common.Constants.BASE_URI);

                var postTask = client.PostAsJsonAsync <InventoryReceiveNoteModel>(Constants.INVENTORY_RECEIVE_NOTE, inventoryReceivingNote);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <InventoryReceivingNote>();
                    readTask.Wait();

                    return(readTask.Result);
                }
                return(null);
            }
        }
示例#2
0
 private InventoryReceivingNote CreateInventoryReceiveNote(InventoryReceiveNoteModel inventoryReceivingNote, string token)
 {
     return(GetApiInventoryReceiveNotes.Post(inventoryReceivingNote, token));
 }
示例#3
0
        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));
        }