public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            this._inflater = inflater;
            View view = inflater.Inflate(Resource.Layout.ic_tab_shopping_list, null);

            ViewModel = new ShoppingListViewModel(ServiceRegistrar.ShoppingService(MainActivity.SqliteConnection));

            _shoppingListView = view.FindViewById <ListView>(Resource.Id.ShoppingListView);

            var newItemEditText = view.FindViewById <EditText>(Resource.Id.NewItemEditText);

            Button addItemButton = view.FindViewById <Button>(Resource.Id.AddButton);

            _shoppingListView.Adapter = ViewModel.Items.GetAdapter(GetItemView);

            addItemButton.Click += delegate
            {
                var title = newItemEditText.Text;

                if (!string.IsNullOrEmpty(title))
                {
                    ViewModel.Add(new Item(title));
                }

                newItemEditText.Text = "";
            };

            _shoppingListView.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs e)
            {
                ViewModel.Remove(this.ViewModel.Items.ElementAt(e.Position));
            };

            return(view);
        }
Beispiel #2
0
        // GET: ShoppingLists/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var shoppingList = await _context.ShoppingLists
                               .Include(s => s.user).Include(x => x.ShoppinglistProducts).ThenInclude(c => c.Product)
                               .FirstOrDefaultAsync(m => m.id == id);

            ShoppingListViewModel viewModel = new ShoppingListViewModel();

            viewModel.Name     = shoppingList.Name;
            viewModel.id       = shoppingList.id;
            viewModel.Products = new List <ProductViewModel>();
            foreach (var item in shoppingList.ShoppinglistProducts)
            {
                ProductViewModel product = new ProductViewModel();
                product.Name   = item.Product.Name;
                product.Amount = item.Amount;
                product.Id     = item.id;
                viewModel.Products.Add(product);
            }


            return(View(viewModel));
        }
Beispiel #3
0
        public ShoppingList()
        {
            this.InitializeComponent();

            ViewModel = new ShoppingListViewModel(ServiceRegistrar.ShoppingService(App.SqliteConnection));
            ShoppingListView.ItemsSource = ViewModel.Items;

            // Developer will want to return to none selection when selected items are zero
            ShoppingListView.SelectionChanged += OnSelectionChanged;

            // With this property we enable that the left edge tap visual indicator shows
            // when user press the listviewitem left edge
            // and also the ItemLeftEdgeTapped event will be fired
            // when user releases the pointer
            ShoppingListView.IsItemLeftEdgeTapEnabled = true;

            // This is event that will be fired when user releases the pointer after
            // pressing on the left edge of the ListViewItem
            ShoppingListView.ItemLeftEdgeTapped += OnEdgeTapped;

            // We set the state of the commands on the appbar
            SetCommandsVisibility(ShoppingListView);

            // This is how devs can handle the back button
            SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
        }
Beispiel #4
0
        /// <summary>
        /// Gets a stores inventory list based on it a store id
        /// </summary>
        /// <param name="storeId">Store id of the store we want to sees inventory</param>
        /// <returns>A list of inventory at a store</returns>
        public ShoppingListViewModel GetStoreInventory(Guid storeId)
        {
            StoreLocation store = _repo.GetStoreById(storeId);

            // TODO: handle this in controller
            if (store == null)
            {
                return(null);
            }

            ShoppingListViewModel storeInventory = new ShoppingListViewModel();

            List <InventoryInfoViewModel> inventoryViewModels = new List <InventoryInfoViewModel>();

            List <Inventory> inventories = _repo.GetStoreInventory(store);

            foreach (Inventory i in inventories)
            {
                inventoryViewModels.Add(_mapper.ConvertInventoryToInventoryInfoViewModel(i));
            }

            storeInventory.StoreLocation = _mapper.ConvertStoreToStoreInfoViewModel(store);
            storeInventory.Inventories   = inventoryViewModels;

            return(storeInventory);
        }
 public void Setup()
 {
     _backendConnection = Substitute.For <IBackendConnection>();
     _findItemViewModel = Substitute.For <IFindItemViewModel>();
     _uut = new ShoppingListViewModel(_backendConnection, _findItemViewModel);
     _obj = new object();
 }
Beispiel #6
0
        private string GetShoppingListViewModel()
        {
            var shoppinglist = _ctx.GetAllShoppingLists().First();
            var listToSend   = new ShoppingListViewModel()
            {
                ShoppingListId = shoppinglist.ShoppingListId,
                Name           = shoppinglist.Name,
                Items          = new List <ItemViewModel>(),
                ListUpdated    = false
            };

            foreach (var item in shoppinglist.Items)
            {
                var viewModelItem = new ItemViewModel()
                {
                    ItemId  = item.ItemId.ToString(),
                    Name    = item.Name,
                    Active  = item.Active,
                    Comment = item.Comment,
                    Deleted = false
                };
                listToSend.Items.Add(viewModelItem);
            }
            var jsonList = JsonConvert.SerializeObject(listToSend);

            return(jsonList);
        }
Beispiel #7
0
        /// <summary>
        /// Adds a new inventory piece to a store based on store and product
        /// </summary>
        /// <param name="inventoryStore">The store we are adding inventory to id</param>
        /// <param name="productName">Name of the product we are adding</param>
        /// <param name="qantityAdded">The number of inventory we are adding</param>
        /// <returns>The updated shopping list with the new inventory</returns>
        public ShoppingListViewModel AddNewInventory(Guid inventoryStore, string productName, int qantityAdded)
        {
            ShoppingListViewModel inventoryList = new ShoppingListViewModel();

            Product product = _repo.GetProductByName(productName);

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

            StoreLocation store = _repo.GetStoreById(inventoryStore);

            Inventory inventory = new Inventory()
            {
                Product         = product,
                StoreLocation   = store,
                ProductQuantity = qantityAdded
            };

            Inventory newInventory = _repo.AddNewInventory(inventory);

            inventoryList = GetStoreInventory(newInventory.StoreLocation.StoreLocationId);

            return(inventoryList);
        }
        public ActionResult AddOrUpdateShoppingList([FromBody] ShoppingListViewModel shoppingList)
        {
            _shoppingListService.AddOrUpdateShoppingList(shoppingList);
            _shoppingListService.ProcessShoppingList(shoppingList);

            return(Ok(new { status = "Ok" }));
        }
        public IActionResult AddToCart(ShoppingListViewModel cart)
        {
            string sessionId = HttpContext.Session.GetString("customerId");

            Guid customerId = new Guid(sessionId);

            CartInfoViewModel updatedCart = _logic.AddToCart(cart.ProductName, cart.QuantityAdded, cart.StoreId, customerId);


            if (updatedCart == null)
            {
                ModelState.AddModelError("Failure", "Customer, Product, Store or Inventory does not exist");
                ShoppingListViewModel storeInventory = _logic.GetStoreInventory(cart.StoreId);
                return(View("Store", storeInventory));
            }

            // if you are trying too add too much quantity
            if (updatedCart.error == 1)
            {
                TempData["ModelState"] = $"{updatedCart.errorMessage}";
                return(RedirectToAction("Store", "Shop", new { id = cart.StoreId }));
            }

            return(View("ViewCart", updatedCart));
        }
        public IActionResult List()
        {
            ShoppingListViewModel vm = new ShoppingListViewModel();

            vm.ShoppingItemRepository = shoppingItemRepository;
            return(View("List", vm));
        }
Beispiel #11
0
        public void WhenRefreshData_ThenClearAndAddItemsFromService()
        {
            // Arrange
            var items = new List <ShoppingListItem>
            {
                new ShoppingListItem {
                    Title = "test3"
                }
            };

            serviceMock
            .Setup(m => m.Get())
            .ReturnsAsync(items);

            var viewModel = new ShoppingListViewModel(viewMock.Object);
            var component = new ShoppingListComponent(viewModel, serviceMock.Object);

            viewModel.ShoppingListItems.Add(new ShoppingListItem {
                Title = "test1"
            });
            viewModel.ShoppingListItems.Add(new ShoppingListItem {
                Title = "test2"
            });

            // Act
            viewModel.RefreshDataCommand.Execute(null);

            // Assert
            Assert.AreEqual(items.Count, viewModel.ShoppingListItems.Count);
            Assert.AreEqual(items[0].Title, viewModel.ShoppingListItems[0].Title);
        }
Beispiel #12
0
        public IShoppingListComponent GetShoppingList()
        {
            var vm      = new ShoppingListViewModel(new ShoppingListView());
            var service = serviceProvider.GetService <IShoppingListService>();

            return(new ShoppingListComponent(vm, service));
        }
Beispiel #13
0
        // The ApplicationBar doesn't support binding so we need to
        // manually handle them in the code behind
        public override void Bind(object context)
        {
            base.Bind(context);

            _viewModel = (ShoppingListViewModel)context;
            _viewModel.CheckoutCommand.CanExecuteChanged += (_s, _e) => UpdateCheckoutButton();

            UpdateCheckoutButton();
        }
Beispiel #14
0
        public void SaveProductList_Clicked(object sender, EventArgs e)
        {
            tapped.Products   += "¡" + ProductEditor.Text;
            ProductEditor.Text = "";
            var vm = new ShoppingListViewModel(tapped);

            vm.SaveShoppingListCommand.Execute(tapped);
            MakeShoppingList();
        }
Beispiel #15
0
 public void SetUp()
 {
     _shoppingListModel = Substitute.For <IShoppingListModel>();
     _shoppingListModel.ShoppingList.Returns(new List <Item>()
     {
         new Item()
     });
     _uut = new ShoppingListViewModel(_shoppingListModel);
 }
 public ActionResult Edit([Bind(Include = "ID,Name,Color,Group")] ShoppingListViewModel shoppingListViewModel)
 {
     if (ModelState.IsValid)
     {
         _svc.Value.UpdateList(shoppingListViewModel);
         return(RedirectToAction("Index"));
     }
     return(View(shoppingListViewModel));
 }
        public IActionResult AddShoppingItem(ShoppingListViewModel shoppingItemVM)
        {
            if (ModelState.IsValid)
            {
                shoppingItemRepository.AddShoppingItem(shoppingItemVM.NewItemName, shoppingItemVM.NewItemShop);
                ModelState.Clear();
            }

            return(List());
        }
        async void OnItemTapped(object sender, ItemTappedEventArgs e)
        {
            ShoppingList tappedItem = e.Item as ShoppingList;

            var shoppingListVM   = new ShoppingListViewModel(tappedItem);
            var shoppingListView = new ShoppingListView(tappedItem);

            shoppingListView.BindingContext = shoppingListVM;

            await Navigation.PushAsync(shoppingListView);
        }
Beispiel #19
0
        public IActionResult ShoppingList(int id)
        {
            OrderLogic.RemoveShoppingCartGame(id);
            ShoppingListViewModel model = new ShoppingListViewModel {
                ShoppingList = OrderLogic.GetShoppingList()
            };

            model.TotalPrice = OrderLogic.GetTotalPrice(model.ShoppingList);

            return(View(model));
        }
        public void Constructor_CollectorReturns4Items_SutHolds4Items()
        {
            _itemCollector.GetAll("Henrik").Returns(new List <Item>()
            {
                new Item(), new Item(), new Item(), new Item()
            });
            _shoppingListModel = new ScheduledShoppingListModel(_itemCollector, _scheduler, _loginModel);
            _sut = new ShoppingListViewModel(_shoppingListModel);

            Assert.That(_sut.ShoppingList.Count, Is.EqualTo(4));
        }
 public void Post([FromBody] ShoppingListViewModel model)
 {
     if (model.ShoppingListId == Guid.Empty)
     {
         model.ShoppingListId = Guid.NewGuid();
         _dbOps.AddNewList(model);
     }
     else
     {
         _dbOps.AddOrUpdateList(model);
     }
 }
        public IActionResult AddNewInventory(AddInventoryViewModel newInventory)
        {
            ShoppingListViewModel currentStoreInventory = _logic.AddNewInventory(newInventory.StoreId, newInventory.ProductName, newInventory.QuantityAdded);

            if (currentStoreInventory == null)
            {
                ModelState.AddModelError("Failure", "Product does not exist");
                StoreListViewModel storeList = _logic.GetStoreList();
                return(View("Index", storeList));
            }
            return(RedirectToAction("Store", "Shop", new { id = newInventory.StoreId }));
        }
        // GET: ShoppingList
        public ActionResult Index()
        {
            //ShoppingListService repo = new ShoppingListService();
            IList <Product>       items = _repo.GetItems();
            ShoppingListViewModel vm    = new ShoppingListViewModel();

            vm.FirstName = "Keigo";
            vm.LastName  = "Ito";
            vm.Products  = items;
            vm.Total     = items.Sum(p => p.Price);
            return(View(vm));
        }
Beispiel #24
0
        public ActionResult AddProductInList(int id)
        {
            // id => id-ul listei curente
            // caut lista in baza de date
            ShoppingList list = ctx.ShoppingLists.Find(id);

            ShoppingListViewModel slVm = new ShoppingListViewModel();

            slVm.ShoppingListId   = list.ShoppingListId;
            slVm.ShoppingProducts = ctx.Products.ToList();
            slVm.Titlu            = list.Titlu;
            return(View(slVm));
        }
Beispiel #25
0
        public IActionResult ShoppingList()
        {
            ShoppingListViewModel model = new ShoppingListViewModel {
                ShoppingList = OrderLogic.GetShoppingList()
            };

            model.TotalPrice = OrderLogic.GetTotalPrice(model.ShoppingList);
            if (OrderLogic.GetShoppingList().Count == 0)
            {
                ModelState.AddModelError("CustomError", "Cart is empty, please add an order before you checkout");
            }
            return(View(model));
        }
Beispiel #26
0
        public IActionResult CreateShoppingList(ShoppingListViewModel model)
        {
            if (ModelState.IsValid)
            {
                //TODO: add methods to validate selecteddays format
                var daysArray    = Array.ConvertAll(model.SelectedDays.Trim().Split(','), int.Parse);
                var dietCalendar = new DietCalendar(model.SelectedFile);
                var shoppingList = new Models.ShoppingList(dietCalendar, daysArray);

                return(View(shoppingList));
            }
            return(View("Index"));
        }
Beispiel #27
0
        void Should_Be_Able_To_Add_Item()
        {
            // Arrange
            var vm   = new ShoppingListViewModel(_shoppingService);
            var item = new Item("some bought item");

            // Act
            vm.Add(item);

            // Assert
            Assert.Contains <Item>(vm.Items, x => x == item);
            Assert.Contains <Item>(_shoppingService.Items, x => x == item);
        }
Beispiel #28
0
        public bool UpdateList(ShoppingListViewModel vm)
        {
            using (var ctx = new ShoppingListDbContext())
            {
                var entity = ctx.ShoppingLists.SingleOrDefault(e => e.ID == vm.ID);

                entity.Name         = vm.Name;
                entity.Color        = vm.Color;
                entity.Group        = (vm.Group == null || vm.Group == "") ? "General" : vm.Group;
                entity.ModifieddUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #29
0
        public void UpdateProducts()
        {
            tapped.Products = "";
            foreach (String product in Lista)
            {
                if (product.Length != 0)
                {
                    tapped.Products += "¡" + product;
                }
            }
            var vm = new ShoppingListViewModel(tapped);

            vm.SaveShoppingListCommand.Execute(tapped);
        }
        // GET: ShoppingList/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShoppingListViewModel shoppingListViewModel = _svc.Value.GetListByID(id);

            if (shoppingListViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(shoppingListViewModel));
        }