private PantryService CreatePantryService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new PantryService(userId);

            return(service);
        }
        // GET: Pantry
        public ActionResult Index()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new PantryService(userId);
            var model   = service.GetPantry();

            return(View(model));
        }
Exemplo n.º 3
0
        public PantryViewModel()
        {
            navManager = PageNavigationManager.Instance;
            AddItemButton_ClickedCommand = new Command(() =>
            {
                navManager.showItemPage(this.pantryList);
            });

            //_service = new PantryMockService();
            _service = new PantryService(new RequestService());
            Task.Run(async() => {
                try
                {
                    PantryModel GetDetails = await _service.GetPantryAsync("abs", 1);
                    PantryList             = new ObservableCollection <PantryItemModel>(GetDetails.Items);
                }
                catch (System.OperationCanceledException ex)
                {
                    Console.WriteLine($"Text load cancelled: {ex.Message}");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            });

            ItemSelectedCommand       = new Command <PantryItemModel>(pantryItemSelected);
            EditItemSelectedCommand   = new Command <PantryItemModel>(pantryEditItemSelected);
            DeleteItemSelectedCommand = new Command <PantryItemModel>(pantryDeleteItemSelected);

            MessagingCenter.Subscribe <ItemViewModel, PantryItemModel>(this, "New Item", (sender, receivedPantryItem) =>
            {
                this.pantryList.Add(receivedPantryItem);
                _service.SetPantryAsync("abs", receivedPantryItem);
            });

            MessagingCenter.Subscribe <EditItemViewModel, PantryItemModel>(this, "Edit Item", (sender, pantryItem) =>
            {
                int index = 0;
                bool done = true;
                while (done)
                {
                    if (this.pantryList[index].Id == pantryItem.Id)
                    {
                        this.pantryList[index] = pantryItem;
                        done = false;
                    }
                    index++;
                }
            });
        }
Exemplo n.º 4
0
 public PantryController(PantryService pantryService, ILogger <PantryController> logger)
 {
     _pantryService = pantryService;
     _logger        = logger;
 }