示例#1
0
        public ShoppingItemDetailViewModel(ShoppingItemModel source, IShoppingCartService shoppingCartService, INavigationService navigationService) : base(source, navigationService)
        {
            ShoppingCartService = shoppingCartService;

            AddToCartCommand       = new ReactiveCommand();
            _addToCartSubscription = AddToCartCommand.Subscribe(AddToCart);
        }
        public async Task <ShoppingItemModel> CreateTemplateItem(IdModel templateId, ShoppingItemModel item, CancellationToken cancellationToken)
        {
            var newItemId = await repository.CreateItem(templateId, item, cancellationToken);

            item.Id = newItemId;

            return(item);
        }
示例#3
0
        private void AdjustItemCount(ShoppingItemModel item, int quantity)
        {
            var count = 0;

            _cart.TryGetValue(item, out count);
            count += quantity;
            SetItemCount(item, count);
        }
示例#4
0
 public ObservableCollection <ShoppingItemModel> RemoveItem(ShoppingItemModel item)
 {
     //wrap try catch - exception when working
     OnPropertyChanged("Remove");
     _currentList.Remove(item);
     CurrentList = _currentList;
     return(CurrentList);
 }
示例#5
0
        public ObservableCollection <ShoppingItemModel> AddItem(ShoppingItemModel item)
        {
            //wrap try catch - exception when working

            _currentList.Add(item);
            CurrentList = _currentList;
            return(CurrentList);
        }
示例#6
0
        public ShoppingCartItemViewModel(ShoppingItemModel source, int count, IShoppingCartService shoppingCartService, INavigationService navigationService) : base(source, navigationService)
        {
            _shoppingCartService = shoppingCartService;
            Count = new ReactiveProperty <int>(count);
            CountAndPriceLabel = Count.CombineLatest(PriceLabel, (cnt, pce) => $"{cnt}x @ {pce} ea.").ToReadOnlyReactiveProperty();

            RemoveCommand       = new ReactiveCommand();
            _removeSubscription = RemoveCommand.Subscribe(RemoveItem);
        }
示例#7
0
        public ShoppingItemDetailPage(ShoppingItemModel item)
        {
            Title = item.Name;

            var navigationService   = IoC.Container.Resolve <INavigationService>();
            var shoppingCartService = IoC.Container.Resolve <IShoppingCartService>();

            BindingContext = new ShoppingItemDetailViewModel(item, shoppingCartService, navigationService);
            Content        = new ShoppingItemDetailView();
        }
        public ShoppingItemDocument(ShoppingItemModel item)
        {
            if (item.Id != null)
            {
                Id = item.Id.ToObjectId();
            }

            Title    = item.Title;
            Quantity = item.Quantity;
            Comment  = item.Comment;
        }
        public ShoppingCartServiceTest()
        {
            _shoppingCartService = new ShoppingCartService();

            _shoppingItemA = new ShoppingItemModel {
                Id = Guid.NewGuid(), Name = "Item A", Description = "Description A", Price = 5.0
            };
            _shoppingItemB = new ShoppingItemModel {
                Id = Guid.NewGuid(), Name = "Item B", Description = "Description B", Price = 250.0
            };
        }
示例#10
0
        public async Task <IdModel> CreateItem(IdModel shoppingListId, ShoppingItemModel item, CancellationToken cancellationToken)
        {
            var newItem = new ShoppingItemDocument(item)
            {
                Id = ObjectId.GenerateNewId(),
            };

            await itemsRepository.CreateItem(shoppingListId.ToObjectId(), newItem, cancellationToken);

            return(newItem.Id.ToIdModel());
        }
示例#11
0
 private void SetItemCount(ShoppingItemModel item, int quantity)
 {
     if (quantity > 0)
     {
         _cart[item] = quantity;
     }
     else
     {
         _cart.Remove(item);
     }
     TriggerUpdate();
 }
示例#12
0
        public ShoppingItemViewModel(ShoppingItemModel source, INavigationService navigationService)
        {
            NavigationService = navigationService;
            Name        = new ReactiveProperty <string>(source.Name);
            Icon        = new ReactiveProperty <string>(source.Icon);
            Description = new ReactiveProperty <string>(source.Description);
            PriceLabel  = new ReactiveProperty <string>($"{source.Price:C}");
            Item        = source;

            ViewDetailsCommand = new ReactiveCommand();
            _viewSubscription  = ViewDetailsCommand.Subscribe(ViewDetails);
        }
        private void SaveAnItem()
        {
            //store the entered item details.
            ItemId       = Guid.NewGuid();
            ItemEditMode = false;
            ItemName     = ItemName;
            ItemQty      = ItemQty;
            ItemPrice    = ItemPrice;

            newItem = new ShoppingItemModel(ItemId, ItemEditMode, ItemName, ItemQty, ItemPrice);

            // Call the delegate AddItem method
            currList.AddItem(newItem);

            //Close the dialogue box/window & may be give user output message.
            CloseDialogTrue();
        }
示例#14
0
 public void RemoveItem(ShoppingItemModel item, int quantity = Int32.MaxValue)
 {
     AdjustItemCount(item, quantity * -1);
 }
示例#15
0
 public void AddItem(ShoppingItemModel item, int quantity = 1)
 {
     AdjustItemCount(item, quantity);
 }
示例#16
0
 public Task UpdateItem(IdModel shoppingListId, ShoppingItemModel item, CancellationToken cancellationToken)
 {
     return(itemsRepository.UpdateItem(shoppingListId.ToObjectId(), new ShoppingItemDocument(item), cancellationToken));
 }
 public Task UpdateShoppingListItem(IdModel shoppingListId, ShoppingItemModel item, CancellationToken cancellationToken)
 {
     return(repository.UpdateItem(shoppingListId, item, cancellationToken));
 }
 public OutputShoppingItemData(ShoppingItemModel item)
     : base(item)
 {
     Id = item.Id.Value;
 }
示例#19
0
 public ShoppingListViewModel()
 {
     _currentList = new ObservableCollection <ShoppingItemModel>();
     _currentItem = new ShoppingItemModel();
 }
示例#20
0
 protected BasicShoppingItemData(ShoppingItemModel item)
 {
     Title    = item.Title;
     Quantity = item.Quantity;
     Comment  = item.Comment;
 }
 public Task UpdateTemplateItem(IdModel templateId, ShoppingItemModel item, CancellationToken cancellationToken)
 {
     return(repository.UpdateItem(templateId, item, cancellationToken));
 }