public void StartPageVisibility()
 {
     _selectedShoppingList = null;
     ChangeVisibility(Visibility.Visible, Visibility.Collapsed, Visibility.Collapsed, Visibility.Collapsed);
     OnPropertyChanged(nameof(SelectedShoppingList));
     RefreshVisiblityProperties();
 }
        /// <summary>
        /// Method to save a shopping list to the local database asynchronously
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public async Task SaveShoppingListAsync(ShoppingListModel list)
        {
            var user = App.MasterController.LoginController.CurrentUser;

            // Return and save the shopping list model object
            await SaveItemsAsync(list);

            // Save the item quantity pairs
            foreach (var item in list.Items)
            {
                item.RemoteDbShoppingListId = list.LocalDbId.Value;
                SaveItemsAsync(item);
            }

            // Create the ListOwnerModel if required
            var listOwnerModel = new ListOwnerModel()
            {
                ShoppingListModelId = list.LocalDbId.Value,
                UserEmail           = user.Email
            };

            // Save the ListOwnerModel if it is unique
            if (!listOwners.Any(lo =>
                                lo.UserEmail == listOwnerModel.UserEmail &&
                                lo.ShoppingListModelId == listOwnerModel.ShoppingListModelId))
            {
                SaveItemsAsync(listOwnerModel);
            }
        }
        //Updates shopping list
        public async Task UpdateShoppingListAsync(UserModel user, ShoppingListModel shoppingList)
        {
            if (user.Position == (int)UserPosition.HasNotHome)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("Home Not Exist", "User is not member of a home");
                errors.Throw();
            }

            user = await _userRepository.GetByIdAsync(user.Id, true);

            ShoppingListModel old = await _shoppingListRepository.GetShoppingListByHomeIdAsync(user.Home.Id, true);

            if (old == null)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("Shopping List Not Exist", "Shopping list is not exist");
                errors.Throw();
            }

            old.List   = shoppingList.List;
            old.Status = shoppingList.Status;

            _shoppingListRepository.Update(old);

            foreach (var friend in user.Home.Users)
            {
                FCMModel fcm = new FCMModel(friend.DeviceId, type: "ShoppingListUpdate");
                fcm.data.Add("UpdatedShoppingList", old);
                await _fcmService.SendFCMAsync(fcm);
            }
        }
示例#4
0
        public int Save(ShoppingListModel shoppingListDTO)
        {
            if (shoppingListDTO.Id == null)
            {
                shoppingListDTO.Id = GetIndex();
            }

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append($"{shoppingListDTO.Id},");
            stringBuilder.Append($"{shoppingListDTO.Name},");
            stringBuilder.Append($"{shoppingListDTO.Comment},");
            stringBuilder.Append($"{shoppingListDTO.Modified}");
            var line = stringBuilder.ToString();

            if (!ContainsLine(line))
            {
                using (StreamWriter file = new StreamWriter(FILE_PATH, true))
                {
                    file.WriteLine(line);
                }
            }

            return((int)shoppingListDTO.Id);
        }
        public async Task <IActionResult> Edit(int id, [Bind("id,Name,UserId")] ShoppingListModel shoppingListModel)
        {
            if (id != shoppingListModel.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(shoppingListModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ShoppingListModelExists(shoppingListModel.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", shoppingListModel.UserId);
            return(View(shoppingListModel));
        }
示例#6
0
        public void AddEmptyShoppingList()
        {
            var sl = new ShoppingListModel();

            shoppingListsModel.AddShoppingList(sl);
            ShoppingLists.Add(new ShoppingListViewModel(sl));
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="list">The shopping list to be evaluated</param>
        public CompareShopsView(ShoppingListModel list)
        {
            InitializeComponent();

            shoppingList = list;
            Title        = shoppingList.Name;

            // Add the picker options
            pickerTextCollection.Add("Total Price");
            pickerTextCollection.Add("Items Matched");
            pickerTextCollection.Add("Distance");

            // Set the refreshing command and calculate the prices for any locations that are currently available.
            ShoppingListsView.IsRefreshing = true;
            ComparePrices(App.MasterController.LocationController.LocationModels);

            // Set binding context
            BindingContext = this;

            // Subscribe to the new location event
            App.MasterController.LocationController.LocationModels.CollectionChanged += ProcessNewLocation;

            // Set the picker item to sort by price
            PickerOrderBy.SelectedItem = pickerTextCollection.First();
        }
示例#8
0
        public async Task CreateShoppingList(ShoppingListModel shoppingList, CancellationToken cancellationToken)
        {
            var document = new ShoppingListDocument(shoppingList);
            await shoppingListCollection.InsertOneAsync(document, cancellationToken : cancellationToken);

            shoppingList.Id = document.Id.ToIdModel();
        }
示例#9
0
        /// <summary>
        /// Method to save a ShoppingListModel to the API database asynchronously
        /// Saves the ItemQuantityPairModels associated to this ShoppingListModel as well
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public async Task SaveShoppingListModelAsync(ShoppingListModel list)
        {
            try
            {
                var url = helper.BaseUrl + ShoppingListModel.UrlSuffix;

                var slistResponse = await helper.SaveItemAsync(list, url);

                list.RemoteDbId = list.RemoteDbId ?? slistResponse?.RemoteDbId;

                url += "/" + list.RemoteDbId + "/" + ItemQuantityPairModel.UrlSuffix;

                foreach (var iqp in list.Items)
                {
                    var iqpResponse = await helper.SaveItemAsync(iqp, url);

                    if (iqp.RemoteDbId == null)
                    {
                        iqp.RemoteDbId = iqpResponse?.RemoteDbId;
                    }
                }
            }
            catch (Exception ex)
            {
                App.Log.Error("SaveShoppingListModelAsync", ex.Message + "\n" + ex.StackTrace);
            }
        }
示例#10
0
 /// <summary>
 /// Method to delete a ShoppingListModel from the API database asynchronously
 /// Returns true if successful, false if not
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public async Task <bool> DeleteShoppingListModelAsync(ShoppingListModel item)
 {
     if (item.RemoteDbId == null)
     {
         return(false);
     }
     return(await helper.DeleteItemAsync(helper.BaseUrl + item.UrlSuffixProperty + "/" + item.RemoteDbId));
 }
 public AddNewListViewModel()
 {
     ItemsList     = new ObservableCollection <string>();
     IsEditMode    = true;
     currentListID = -1;
     Setup();
     currentShoppingListModel = new ShoppingListModel();
 }
        public async Task <Guid> Create(ShoppingListModel shoppingListModel)
        {
            var shoppingListEntity = _mapper.Map <ShoppingListEntity>(shoppingListModel);
            await _dbRepository.AddAsync(shoppingListEntity);

            await _dbRepository.SaveChangesAsync();

            return(shoppingListEntity.Id);
        }
        public async Task <IActionResult> UpdateShoppingList([FromBody] ShoppingListModel shoppingList)
        {
            string    token = Request.Headers["Authorization"].ToString().Substring("Bearer ".Length).Trim();
            UserModel user  = await _jwtTokenService.GetUserFromTokenStrAsync(token);

            await _shoppingListService.UpdateShoppingListAsync(user, shoppingList);

            return(Ok());
        }
示例#14
0
 public static DbShoppingList Convert(this ShoppingListModel item)
 {
     return(new DbShoppingList
     {
         Id = item.Id,
         Name = item.Name,
         CreateTime = item.CreateTime
     });
 }
        public async Task <IActionResult> Synchronize()
        {
            string    token = Request.Headers["Authorization"].ToString().Substring("Bearer ".Length).Trim();
            UserModel user  = await _jwtTokenService.GetUserFromTokenStrAsync(token);

            ShoppingListModel res = await _shoppingListService.SynchronizeShoppingListAsync(user);

            return(Ok(res));
        }
示例#16
0
 public static ShoppingListApiModel Convert(this ShoppingListModel model)
 {
     return(new ShoppingListApiModel
     {
         Id = model.Id,
         Name = model.Name,
         CreateTime = model.CreateTime
     });
 }
 public AddNewListViewModel(ShoppingListModel shoppingList)
 {
     ListName      = shoppingList.Name;
     ItemsList     = shoppingList.Items;
     currentListID = shoppingList.ID;
     IsEditMode    = false;
     Setup();
     currentShoppingListModel = shoppingList;
 }
示例#18
0
        public KeyValuePair <string, int> DeleteItemInShoppingList(ShoppingListModel shoppingListModel)
        {
            KeyValuePair <string, int> kp = new KeyValuePair <string, int>(shoppingListModel.Name, shoppingListModel.quantity);

            if (_shoppingList.ContainsKey(kp.Key))
            {
                _shoppingList.Remove(kp.Key);
            }
            return(kp);
        }
示例#19
0
        /// <summary>
        /// Method to add a new owner with the given email to the given shopping list on the API
        /// </summary>
        /// <param name="list"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public async Task <bool> AddShoppingListModelOwnerAsync(ShoppingListModel list, string email)
        {
            var url = helper.BaseUrl + ListOwnerModel.UrlSuffix;

            return(await helper.SaveItemAsync(url, new List <KeyValuePair <string, string> >(1)
            {
                new KeyValuePair <string, string>("email", email),
                new KeyValuePair <string, string>("slist_id", list.RemoteDbId.ToString())
            }));
        }
 public void UpdateItem(ShoppingListModel shoppingList)
 {
     try
     {
         _shoppingListStorage[shoppingList.Name] = shoppingList.Quantity;
     }
     catch (Exception e)
     {
         throw(new Exception(e.Message));
     }
 }
示例#21
0
        public async Task <IActionResult> Put([FromBody] ShoppingListModel value)
        {
            var shoppinglist = mapper.Map <ShoppingList>(value);
            var res          = await storageHandler.Update(shoppinglist);

            if (res == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            return(Ok(mapper.Map <ShoppingListModel>(res)));
        }
示例#22
0
        public async Task <IActionResult> Post([FromBody] ShoppingListModel shoppinglistmodel)
        {
            var shoppinglist = mapper.Map <ShoppingList>(shoppinglistmodel);
            var addRes       = await storageHandler.Insert(shoppinglist);

            if (addRes == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            return(Ok(mapper.Map <ShoppingListModel>(addRes)));
        }
 public void AddItemToShoppingList(ShoppingListModel shoppingList)
 {
     try
     {
         _shoppingListStorage.Add(shoppingList.Name, shoppingList.Quantity);
     }
     catch (Exception e)
     {
         throw(new Exception(e.Message));
     }
 }
示例#24
0
        /// <summary>
        /// Method to raise a new shopping list event
        /// </summary>
        private void RaiseNewShoppingListEvent()
        {
            var newShoppingListModel = new ShoppingListModel()
            {
                Name        = this.NameField,
                DateCreated = DateTime.Now.ToString()
            };

            App.MasterController.ShoppingListController.SaveShoppingListModel(newShoppingListModel);

            callback?.Invoke(this, new ShoppingListEventArgs(newShoppingListModel));
        }
示例#25
0
        /// <summary>
        /// Method to save the given shopping list to the local database and api
        /// Attempts to get the api remote database id to save into the local database
        /// </summary>
        /// <param name="list"></param>
        public async void SaveShoppingListModel(ShoppingListModel list)
        {
            SaveShoppingListToDatabase(list);

            await apiHelper.SaveShoppingListModelAsync(list);

            // Resave with remote db id
            SaveShoppingListToDatabase(list);

            // Refresh nearby location ipls
            App.MasterController.LocationController.GetNearbyLocations();
        }
示例#26
0
        public void AddItemsToShoppingList(ShoppingList shoppingList)
        {
            ShoppingListModel shoppingListModel = new ShoppingListModel {
                ID           = (shoppingList.GetHashCode()),
                ShoppingList = new ShoppingList {
                    Name     = shoppingList.Name,
                    Quantity = shoppingList.Quantity
                }
            };

            _contextDB.Insert(shoppingListModel);
        }
        public async Task <IActionResult> Create([Bind("id,Name,UserId")] ShoppingListModel shoppingListModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shoppingListModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", shoppingListModel.UserId);
            return(View(shoppingListModel));
        }
示例#28
0
        public KeyValuePair <string, int> AddItemToShoppingList(ShoppingListModel shoppingListModel)
        {
            KeyValuePair <string, int> kp = new KeyValuePair <string, int>(shoppingListModel.Name, shoppingListModel.quantity);

            switch (_shoppingList.ContainsKey(kp.Key))
            {
            case true:
                _shoppingList[kp.Key] = kp.Value;
                break;

            case false:
                _shoppingList.Add(kp.Key, kp.Value);
                break;
            }
            return(kp);
        }
示例#29
0
        /// <summary>
        /// Method to add a new owner to the given ShoppingList
        /// </summary>
        /// <param name="list"></param>
        /// <param name="newUserEmail"></param>
        public async Task <bool> AddOwnerAsync(ShoppingListModel list, string newUserEmail)
        {
            var apiResponse = await apiHelper.AddShoppingListModelOwnerAsync(list, newUserEmail);

            // Create a ListOwnerModel in the local database if the api responds with success
            if (apiResponse)
            {
                databaseHelper.SaveItemsAsync <ListOwnerModel>(new ListOwnerModel()
                {
                    ShoppingListModelId = list.LocalDbId.Value,
                    UserEmail           = newUserEmail
                });
            }

            return(apiResponse);
        }
示例#30
0
        /// <summary>
        /// Method to get the ItemQuantityPairModels for a given ShoppingListModel from the API database asynchronously
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        private async Task GetItemQuantityPairModelsAsync(ShoppingListModel list)
        {
            try
            {
                var url = helper.BaseUrl + ShoppingListModel.UrlSuffix + "/" + list.RemoteDbId + "/" +
                          ItemQuantityPairModel.UrlSuffix;

                var items = await helper.RefreshDataAsync <ItemQuantityPairModel>(url);

                list.AddItems(items);
            }
            catch (Exception e)
            {
                App.Log.Error("GetItemQuantityPairModelsAsync", e.StackTrace);
            }
        }