public async Task <bool> Delete(ExpenseCollectionModel nm) { try { var obj = RequestConverter.Instance.ConvertToNoteCollectionRequest(_userInformations.Guid, PossibleActions.Delete, new List <ExpenseCollectionModel>() { nm }); var res = await _dataService.PostExpenseCollection(obj); nm.PendingAction = !res.IsSuccessfull ? PendingAction.Remove : PendingAction.None; if (_dataModel.Collections.Contains(nm)) { _dataModel.Collections.Remove(nm); } if (nm.PendingAction != PendingAction.None) { _dataModel.DeletedCollections.Add(nm); } return(await SaveExpenseCollectionsToStorage() && res.IsSuccessfull); } catch (Exception ex) { LogHelper.Instance.LogException(ex, this); } return(false); }
private ExpenseCollectionEntity ConvertToNoteCollectionEntity(ExpenseCollectionModel collection) { return(new ExpenseCollectionEntity() { Guid = collection.Guid, Name = collection.Name, CreateTime = collection.CreateTime }); }
private async void AddExpenseCollection() { var newExpenseCollection = new ExpenseCollectionModel() { Guid = Guid.NewGuid(), Name = NewExpenseCollection, CreateTime = DateTime.Now }; NewExpenseCollection = ""; await _expenseRepository.Save(newExpenseCollection); ActiveCollection = newExpenseCollection; }
private async void RemoveExpenseCollection(ExpenseCollectionModel model) { if (model == ActiveCollection) { var index = ExpenseCollections.IndexOf(ActiveCollection); if (index == 0) { ActiveCollection = ExpenseCollections[1]; } else { ActiveCollection = ExpenseCollections[--index]; } } await _expenseRepository.Delete(model); RaisePropertyChanged(() => TotalExpenseAmount); Messenger.Default.Send(Messages.ExpenseChanged); }
public async Task <ObservableCollection <ExpenseCollectionModel> > GetCollections() { try { if (await RetrieveUserInformationsFromStorage()) { if (await RetrieveNoteCollectionsFromStorage()) { foreach (var noteCollection in _dataModel.Collections) { foreach (var note in noteCollection.Expenses) { note.ExpenseCollection = noteCollection; } foreach (var note in noteCollection.DeletedExpenses) { note.ExpenseCollection = noteCollection; } } foreach (var noteCollection in _dataModel.DeletedCollections) { foreach (var note in noteCollection.Expenses) { note.ExpenseCollection = noteCollection; } foreach (var note in noteCollection.DeletedExpenses) { note.ExpenseCollection = noteCollection; } } } else { _dataModel = new DataModel(); await SyncExpenses(); } } else { _dataModel = new DataModel(); var coll = new ExpenseCollectionModel() { Name = "Meals", Guid = Guid.NewGuid(), PendingAction = PendingAction.AddOrUpdate }; foreach (var note in coll.Expenses) { note.ExpenseCollection = coll; } _dataModel.Collections.Add(coll); await SyncExpenses(); await SaveExpenseCollectionsToStorage(); } } catch (Exception ex) { LogHelper.Instance.LogException(ex, this); } return(_dataModel.Collections); }
private void InsertIntoList(ObservableCollection <ExpenseCollectionModel> list, ExpenseCollectionModel model) { var found = false; for (int i = 0; i < list.Count; i++) { if (string.Compare(model.Name, list[i].Name, StringComparison.Ordinal) < 0) { list.Insert(i, model); found = true; break; } } if (!found) { list.Add(model); } }
public void WriteValues(ExpenseCollectionEntity expense, ExpenseCollectionModel model) { model.Name = expense.Name; model.CreateTime = expense.CreateTime; }
private void EvaluateSelectMessage(ExpenseCollectionModel obj) { ActiveCollection = obj; }
private async void SaveExpenseCollection(ExpenseCollectionModel model) { await _expenseRepository.Save(model); }
public bool CanSaveExpenseCollection(ExpenseCollectionModel model) { return(!string.IsNullOrEmpty(model?.Name)); }
public bool CanRemoveExpenseCollection(ExpenseCollectionModel model) { return(ExpenseCollections.Count > 1); }