Ejemplo n.º 1
0
 public async Task <IShoppingItem> UpdateProductAsync(Guid id, IShoppingItem item)
 {
     if (item is null)
     {
         throw new ArgumentNullException(nameof(item), "Item can't be null");
     }
     try
     {
         if (item.Image is not null)
         {
             string fileName = UploadFile(item.Image);
             item.UriImg = fileName;
         }
         item.Id = id;
         return(await repository.UpdateAsync((ShoppingItem)item));
     }
     catch (DbUpdateException e)
     {
         logger.LogWarning(e, "Item updating error - db update issue.");
         throw;
     }
     catch (Exception e)
     {
         logger.LogError(e, "Item updating error - db unknown issue.");
         throw;
     }
     //return item switch
     //{
     //    BackItem i => await backItemRepository.UpdateAsync(i),
     //    HeadItem i => await headItemRepository.UpdateAsync(i),
     //    PrimaryWeapon i => await primaryWeaponRepository.UpdateAsync(i),
     //    SecondaryWeapon i => await secondaryWeaponRepository.UpdateAsync(i),
     //    _ => LogErrorAndReturnNeeded<object>($"Attempted to update an unhandeld type: {item.GetType().Name}")
     //};
 }
Ejemplo n.º 2
0
        public IShoppingBasketItem AddItem(IShoppingItem item, int quantity)
        {
            var items = (List <IShoppingBasketItem>)Items;

            if (quantity < 1)
            {
                throw new ArgumentOutOfRangeException("Item quantity cannot be less than 1");
            }

            RemoveItem(item); // if exists.

            var basketItem = CreateBasketItem(item.Id, item.Name, item.UnitPrice, quantity, item.TaxRules);

            Total = SubTotal += basketItem.SubTotal;

            basketItem.PublishUpdate(UpdateType.Add);

            CalculateTax(this, basketItem);
            items.Add(basketItem);

            Updated?.Invoke(
                this,
                new ShoppingUpdatedEventArgs(this, UpdateType.Add)
                );

            return(basketItem);
        }
Ejemplo n.º 3
0
 public async Task <IShoppingItem> AddProductAsync(IShoppingItem item)
 {
     if (item is null)
     {
         throw new ArgumentNullException(nameof(item), "Item can't be null");
     }
     try
     {
         if (item.Image is null)
         {
             throw new ItemCreatedWithoutImageException("Can't create item without image!");
         }
         string fileName = UploadFile(item.Image);
         item.UriImg = fileName;
         return(await repository.AddAsync((ShoppingItem)item));
     }
     catch (ItemCreatedWithoutImageException e)
     {
         logger.LogInformation(e, "Item creation declined - no image.");
         throw;
     }
     catch (DbUpdateException e)
     {
         logger.LogWarning(e, "Item creation error - db update issue.");
         throw;
     }
     catch (Exception e)
     {
         logger.LogError(e, "Item creation error - db unknown issue.");
         throw;
     }
 }
Ejemplo n.º 4
0
        public static TinyShopping.ApplicationModels.Item ToModel(this IShoppingItem item)
        {
            var ret = new TinyShopping.ApplicationModels.Item();

            item.MemberviseCopyTo(ret);
            return(ret);
        }
        public void SetShoppingItem(long shoppingId, IShoppingItem shoppingItem)
        {
            Init();

            if (shoppingItem.Id != 0)
            {
                var rawValues = shoppingItems.GetString(BuildShoppingItemKey(shoppingId), "");
                IDictionary <string, string> values;

                if (rawValues == "")
                {
                    values = new Dictionary <string, string>();
                }
                else
                {
                    values = JsonConvert.DeserializeObject <IDictionary <string, string> >(rawValues);
                }

                values[BuildShoppingItemSubKey(shoppingItem.Id)] = JsonConvert.SerializeObject(shoppingItem);

                shoppingItems.Edit()
                .PutString(BuildShoppingItemKey(shoppingId), JsonConvert.SerializeObject(values))
                .Commit();
            }
        }
Ejemplo n.º 6
0
        public void CanCheckIfItemExistsInManager()
        {
            IShoppingItem itemToAdd = CreateFakeTaxItem("Playstation 4");

            _shoppingCart.Add(itemToAdd);

            Assert.AreNotEqual(_shoppingCart.CheckIfItemExistsInCart("Playstation 4"), null);
        }
Ejemplo n.º 7
0
 public ProductListItem(IShoppingItem shoppingItem)
 {
     Name     = shoppingItem.Name;
     Quantity = shoppingItem.Quantity.ToString();
     BarCode  = shoppingItem.BarCode;
     Price    = shoppingItem.Price;
     Total    = shoppingItem.Price * shoppingItem.Quantity;
     Image    = shoppingItem.Image;
 }
Ejemplo n.º 8
0
        public void CanAddItemToTaxItemManager()
        {
            IShoppingItem itemToAdd = CreateFakeTaxItem("Playstation 5");

            _shoppingCart.Add(itemToAdd);

            var items = _shoppingCart.TaxableItems;

            Assert.AreEqual(items.Contains(itemToAdd), true);
        }
Ejemplo n.º 9
0
        public async Task <IShoppingItem> GetItemByIDAsync(Guid itemID)
        {
            IShoppingItem item = await repository.GetItemByIdAsync(itemID);

            if (item is not null)
            {
                return(item);
            }
            throw new KeyNotFoundException("Could not find an item with the given ID!");
        }
Ejemplo n.º 10
0
        public ShoppingListVM(IShoppingList model)
        {
            _model         = model;
            AddItemCommand = new Command(() =>
            {
                IShoppingItem newItem = _model.CreateNewItem();
                _model.Items.Add(newItem);
                Items.Add(new ShoppingItemVM(newItem));
            });

            Items = new ObservableCollection <ShoppingItemVM>(model.Items.Select(modelItem => new ShoppingItemVM(modelItem)));
        }
Ejemplo n.º 11
0
 internal bool Add(IShoppingItem si)
 {
     if (si == this)
     {
         return(false);
     }
     if (Kind == null)
     {
         Kind = si.Kind;
     }
     Amount += si.Amount;
     return(true);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Runs the console application
        /// </summary>
        /// <param name="serviceProvider">the service provider</param>
        private static void RunApp(ServiceProvider serviceProvider)
        {
            ShoppingCart taxItemManager = new ShoppingCart();

            bool finishedEnteringInput = false;

            while (!finishedEnteringInput)
            {
                string name = ReadTaxItemName();

                Taxable taxSelection = ReadTaxSelection(serviceProvider);

                decimal priceWithoutTax = ReadPriceWithoutTax();

                ITaxCalculator taxCalculator = serviceProvider.GetService <ITaxCalculator> ();

                IShoppingItem existingItem = taxItemManager.CheckIfItemExistsInCart(name);
                if (existingItem != null)
                {
                    Console.WriteLine();
                    Console.WriteLine($"Item with name {existingItem.ItemName} already exists, using prexisiting item price {existingItem.PriceWithoutTax}");
                    priceWithoutTax = existingItem.PriceWithoutTax;
                    taxSelection    = existingItem.Taxable;
                }

                ShoppingItem taxableItem = new ShoppingItem(
                    taxSelection,
                    priceWithoutTax,
                    name,
                    taxCalculator
                    );

                taxItemManager.Add(taxableItem);

                Console.WriteLine();
                Console.Write("Add another item? y/n: ");

                ConsoleKeyInfo key = Console.ReadKey();
                if (key.KeyChar == 'n')
                {
                    finishedEnteringInput = true;
                }

                Console.WriteLine();
            }
            IReceiptPrinter receiptPrinter = serviceProvider.GetService <IReceiptPrinter> ();

            receiptPrinter.PrintReceipt(taxItemManager.TaxableItems);
        }
Ejemplo n.º 13
0
        public async Task <ActionResult <ShoppingItemDTO> > Get(Guid id)
        {
            try
            {
                IShoppingItem item = await productsService.GetItemByIDAsync(id);

                return(Ok(ShoppingItemDTO.FromDbModel(item)));
            }
            catch (KeyNotFoundException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(Problem(e.Message, statusCode: StatusCodes.Status500InternalServerError));
            }
        }
Ejemplo n.º 14
0
        public async Task <IShoppingItem> RemoveProductAsync(Guid id)
        {
            try
            {
                IShoppingItem item = await GetItemByIDAsync(id);

                return(await repository.RemoveAsync((ShoppingItem)item));
            }
            catch (DbUpdateException e)
            {
                logger.LogWarning(e, "Item removing error - db update issue.");
                throw;
            }
            catch (Exception e)
            {
                logger.LogError(e, "Item removing error - db unknown issue.");
                throw;
            }
        }
Ejemplo n.º 15
0
        public IShoppingBasketItem RemoveItem(IShoppingItem item)
        {
            var items      = (List <IShoppingBasketItem>)Items;
            var basketItem = items.FirstOrDefault(i => i.Id == item.Id);

            if (basketItem == null)
            {
                return(null);
            }

            items.Remove(basketItem);
            basketItem.PublishUpdate(UpdateType.Remove);

            Updated?.Invoke(
                this,
                new ShoppingUpdatedEventArgs(this, UpdateType.Remove)
                );

            return(basketItem);
        }
Ejemplo n.º 16
0
 public IShoppingBasketItem AddItem(IShoppingItem item)
 => AddItem(item, 1);
Ejemplo n.º 17
0
 public void Add(IShoppingItem item)
 {
     itemsToDisplay.Add(new ProductListItem(item));
     NotifyItemToDisplayChanged();
 }
Ejemplo n.º 18
0
        public ShoppingItemVM(IShoppingItem model)
        {
            _model = model;

            TogglePurchasedCommand = new Command(() => togglePurchased());
        }
Ejemplo n.º 19
0
 public ShoppingItem(IShoppingItem si)
     : this(si.Pluno, si.Amount, si.Price, si.Kind)
 {
 }
Ejemplo n.º 20
0
 public void OnAddedItem(IShoppingItem item)
 {
     this.RaisePropertyChanged("TotalSum");
 }
Ejemplo n.º 21
0
 private void OnAddCurrentItem(IShoppingItem item)
 {
     ProductList.Add(item);
     CurrentProduct.Clear(clearCode: true);
     ShoppingActions.OnAddedItem(item);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Adds a taxable item to the list of taxable items
 /// </summary>
 /// <param name="taxableItem">the taxable item to be added</param>
 public void Add(IShoppingItem taxableItem)
 {
     _taxableItems.Add(taxableItem);
 }