Exemple #1
0
        public static async Task GetTodosAndCategories()
        {
            bool updatedCategories = false;
            bool updatedTodos      = false;

            if (!LocalData.TSCategoriesList.Any())
            {
                updatedCategories          = true;
                LocalData.TSCategoriesList = await WebApiFunctions.CmdGetAllCategories();
            }

            if (!LocalData.TsTodosList.Any())
            {
                updatedTodos          = true;
                LocalData.TsTodosList = await WebApiFunctions.CmdGetAllTodos();

                foreach (var item in LocalData.TsTodosList.Where(x => x.HasDueDate == false))
                {
                    item.DueDate = new DateTime();
                }

                foreach (var item in LocalData.TsTodosList.Where(x => x.HasRemindDate == false))
                {
                    item.RemindDate = new DateTime();
                }


                foreach (var item in LocalData.TsTodosList.Where(x => x.HasDueDate))
                {
                    item.DaysLeft = (short)(item.DueDate - ToLocalDate(DateTime.Now)).TotalDays;
                }

                for (int i = 0; i < LocalData.TsTodosList.Count; i++)
                {
                    LocalData.TsTodosList[i].N = i + 1;
                }


                foreach (var item in LocalData.TsTodosList)
                {
                    item.Category = GetCategoryName(item.CategoryID);
                }
            }


            if (updatedCategories || updatedTodos)
            {
                if (LocalData.TSCategoriesList.Any())
                {
                    for (int i = 0; i < LocalData.TSCategoriesList.Count; i++)
                    {
                        LocalData.TSCategoriesList[i].N          = i + 1;
                        LocalData.TSCategoriesList[i].TodosCount = LocalData.TsTodosList.Count(x => x.CategoryID == LocalData.TSCategoriesList[i].ID);
                    }
                }
            }
        }
Exemple #2
0
        public static string GetCategoryName(Guid CategoryID)
        {
            string result = string.Empty;

            if (!LocalData.TSCategoriesDictionary.Any())
            {
                LocalData.TSCategoriesList = WebApiFunctions.CmdGetAllCategories().Result;
            }
            else
            {
                LocalData.TSCategoriesDictionary.TryGetValue(CategoryID, out result);
            }

            return(result);
        }