public async Task <IActionResult> AddCart([FromBody] Cart value) { var _item = await _itemRepository.GetItemMasterAsync(value.ItemID); if (value.Qty > _item.ItemQty) // To Check customer qty in available stock { return(Ok(new { Message = $"No Stock, Available Qty : { _item.ItemQty }" })); } var _oldCart = await _repository.GetCartsByCustomerItemAsync(value.CustID, value.ItemID); if (_oldCart != null) //check if same item already exist for the same customer { if ((_oldCart.Qty + value.Qty) > _item.ItemQty) // To Check customer qty in available stock { return(Ok(new { Message = $"Already you have {_oldCart.Qty} items in your cart and requested item qty is {value.Qty}, Total Requested Qty : {(_oldCart.Qty + value.Qty)} , Total Available Qty : { _item.ItemQty }" })); } var _Cart = await _repository.UpdateCartAsync(value); //for updating qty with existing cart return(Ok(_Cart)); } else { var _Cart = await _repository.AddCartAsync(value); //for adding new item into cart return(Ok(_Cart)); } }