Beispiel #1
0
        public async Task <List <TodoListModel> > GetAllLists()
        {
            try
            {
                var lists = await database.QueryAsync <TodoListModel>("SELECT * FROM TodoList");

                foreach (TodoListModel list in lists)
                {
                    var todoItems = await GetTodoItems(list.Id);

                    if (todoItems != null && todoItems.Count > 0)
                    {
                        list.TodoItems = new List <TodoItemModel>(todoItems);
                    }
                    else
                    {
                        list.TodoItems = new List <TodoItemModel>();
                    }
                }

                return(lists);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(null);
            }
        }
Beispiel #2
0
        public async Task <bool> ChangeListActiveState(TodoListModel list)
        {
            try
            {
                list.Active = !list.Active;

                if (list.Active)
                {
                    var allLists = await database.QueryAsync <TodoListModel>("SELECT * FROM TodoList");

                    foreach (TodoListModel todolist in allLists)
                    {
                        todolist.Active = false;
                        await database.UpdateAsync(todolist);
                    }
                }

                await database.UpdateAsync(list);

                return(true);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(false);
            }
        }
Beispiel #3
0
        public async Task <TodoListModel> GetList(Guid listId)
        {
            try
            {
                var list = await database.QueryAsync <TodoListModel>("SELECT * FROM TodoList WHERE Id = ?", listId);

                if (list != null && list.Count > 0)
                {
                    var todoItems = await GetTodoItems(list[0].Id);

                    if (todoItems != null && todoItems.Count > 0)
                    {
                        list[0].TodoItems = new List <TodoItemModel>(todoItems);
                    }
                    else
                    {
                        list[0].TodoItems = new List <TodoItemModel>();
                    }
                    var listTodoItems = await GetTodoItems(list[0].Id);

                    return(list[0]);
                }

                return(null);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(null);
            }
        }
Beispiel #4
0
 public void OnNavigatedTo(INavigationParameters parameters)
 {
     try
     {
         Task.Run(async() => await RefreshTodoLists());
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #5
0
 public static void RegisterServices(IContainerRegistry containerRegistry)
 {
     try
     {
         containerRegistry.RegisterSingleton <ICacheService, CacheService>();
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #6
0
 public TodoItemView()
 {
     try
     {
         InitializeComponent();
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #7
0
 public virtual async Task RefreshTodoLists()
 {
     try
     {
         TodoLists = await cachingService.GetAllLists();
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #8
0
 protected override void RegisterTypes(IContainerRegistry containerRegistry)
 {
     try
     {
         IoCServices.RegisterServices(containerRegistry);
         IoCNavigation.RegisterViewsAndViewModels(containerRegistry);
     }
     catch (System.Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #9
0
 public void OnNavigatedTo(INavigationParameters parameters)
 {
     try
     {
         TodoList = parameters.GetValue <TodoListModel>("todolist");
         Task.Run(async() => await RefreshTodoLists());
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #10
0
 public TodoViewModel(ICacheService cacheService, INavigationService navigationService)
 {
     try
     {
         this.cachingService    = cacheService;
         this.navigationService = navigationService;
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #11
0
        public async Task <TodoItemModel> GetTodoItem(Guid todoId)
        {
            try
            {
                var item = await database.QueryAsync <TodoItemModel>("SELECT * FROM TodoItem WHERE Id = ?", todoId);

                return(item[0] ?? null);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(null);
            }
        }
Beispiel #12
0
        public async Task <bool> DeleteTodoItem(TodoItemModel todoItem)
        {
            try
            {
                await database.DeleteAsync(todoItem);

                return(true);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(false);
            }
        }
Beispiel #13
0
        public async Task <List <TodoItemModel> > GetTodoItems(Guid todoListId)
        {
            try
            {
                var todoItems = await database.QueryAsync <TodoItemModel>($"SELECT * FROM TodoItem where ListId = ?", todoListId);

                return(todoItems ?? null);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(null);
            }
        }
Beispiel #14
0
        private async Task GenericAction(string action)
        {
            try
            {
                switch (action)
                {
                case "save":
                {
                    if (IsEdit && IsTodoItemSave)
                    {
                        todoList.TodoItems.Where(item => item.Id == todoItemEditId).FirstOrDefault().Name = Name;
                        await parentViewModel.cachingService.SaveList(todoList);
                    }
                    else if (IsTodoItemSave)
                    {
                        todoList.TodoItems.Add(new TodoItemModel(Name));
                        await parentViewModel.cachingService.SaveList(todoList);
                    }
                    else if (IsEdit)
                    {
                        todoList.Name = Name;
                        await parentViewModel.cachingService.SaveList(todoList);
                    }
                    else
                    {
                        await parentViewModel.cachingService.SaveList(new TodoListModel(Name));
                    }

                    await parentViewModel.RefreshTodoLists();

                    await PopupNavigation.Instance.PopAsync();

                    break;
                }

                case "cancel":
                {
                    await PopupNavigation.Instance.PopAsync();

                    break;
                }
                }
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
            }
        }
Beispiel #15
0
 public CacheService()
 {
     try
     {
         if (database == null)
         {
             database = new SQLiteAsyncConnection(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Todo.db3"));
             database.CreateTableAsync <TodoListModel>().Wait();
             database.CreateTableAsync <TodoItemModel>().Wait();
         }
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #16
0
        public async Task <bool> CompleteList(TodoListModel list)
        {
            try
            {
                list.Active    = false;
                list.Completed = true;
                await SaveList(list);

                return(true);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(false);
            }
        }
Beispiel #17
0
        public override async Task RefreshTodoLists()
        {
            try
            {
                if (TodoList != null)
                {
                    TodoList = await cachingService.GetList(TodoList.Id);

                    IsEmpty = TodoList.TodoItems == null || TodoList.TodoItems.Count <= 0;
                }
                else
                {
                    IsEmpty = true;
                }
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
            }
        }
Beispiel #18
0
        public async Task <bool> DeleteList(TodoListModel list)
        {
            try
            {
                if (list.TodoItems != null)
                {
                    foreach (TodoItemModel todoItem in list.TodoItems)
                    {
                        await database.DeleteAsync(todoItem);
                    }
                }

                await database.DeleteAsync(list);

                return(true);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(false);
            }
        }
Beispiel #19
0
        public async Task <bool> SaveList(TodoListModel list)
        {
            try
            {
                var existingList = await GetList(list.Id);

                if (existingList != null)
                {
                    if (list.TodoItemsEdited)
                    {
                        list.TodoItemsEdited = false;

                        foreach (TodoItemModel item in list.TodoItems)
                        {
                            await DeleteTodoItem(item);
                        }

                        foreach (TodoItemModel item in list.TodoItems)
                        {
                            await SaveTodoItem(item, list.Id);
                        }
                    }

                    await database.UpdateAsync(list);
                }
                else
                {
                    await database.InsertAsync(list);
                    await ChangeListActiveState(list);
                }

                return(true);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(false);
            }
        }
Beispiel #20
0
        public async Task <bool> SaveTodoItem(TodoItemModel todoItem, Guid listId)
        {
            var existingItem = await GetTodoItem(todoItem.Id);

            try
            {
                if (existingItem != null)
                {
                    await database.UpdateAsync(todoItem);
                }
                else
                {
                    todoItem.ListId = listId;
                    await database.InsertAsync(todoItem);
                }
                return(true);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(false);
            }
        }