Exemplo n.º 1
0
        /// <summary>
        /// Add an item to the cart
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="buyerQuantity"></param>
        /// <param name="pounds"></param>
        public ResultVM AddItemToCart(uint code, ushort buyerQuantity, double pounds = 0)
        {
            var ResultVM = new ResultVM();

            try
            {
                var item = stockData.GetItemByCode(code);
                if (item != null && item.Units >= buyerQuantity)
                {
                    var buyerItem = mapper.Map <BuyerItemVM>(item);
                    buyerItem.FreeUnits = GetFreeItemCount(buyerItem);
                    buyerItem.Price     = GetFinalItemPrice(buyerItem);
                    stockService.ReduceStockAsUnits(buyerItem.Code, buyerItem.Units);
                    shoppingCart.Items.Add(buyerItem);
                    ResultVM.Message = Message.ItemAddedToCart;
                }
                else
                {
                    ResultVM.Message = Message.InsufficientItemQuantity;
                }
            }
            catch (Exception ex)
            {
                ResultVM.Message = Message.ItemNotAddedToCart;
                throw;
            }
            return(ResultVM);
        }
Exemplo n.º 2
0
 public ResultVM GetItemByCode(uint code)
 {
     try
     {
         var item = stockData.GetItemByCode(code);
         if (item != null)
         {
             result.Message = Message.ItemFound;
             result.Result  = item;
         }
         else
         {
             result.Message = Message.ItemNotExists;
         }
     }
     catch (Exception ex)
     {
         result.Message = Message.ErrorGettingItem;
     }
     return(result);
 }