示例#1
0
        public ICategoryModel CreateNewCategory()
        {
            var entity = new Category
            {
                HexColor = "#ffb900",
                Type     = CategoryType.Expense
            };

            return(new CategoryModel(entity, _service, isNew: true));
        }
示例#2
0
        public async Task UpdateCategories(CancellationToken token)
        {
            //If user is logged in then sync accounts
            if (_service.IsAuthorized)
            {
                var categories = await _service.GetCategories(true, token);

                if (categories != null)
                {
                    foreach (var category in categories)
                    {
                        var categoryEntity = new Category
                        {
                            Id             = category.Id,
                            Title          = category.Title,
                            HexColor       = category.HexColor,
                            Type           = category.Type,
                            IsArchived     = category.IsArchived,
                            IsDeleted      = category.IsDeleted,
                            IsSynchronized = true
                        };

                        if (await _repository.HaveCategories(category.Id, token))
                        {
                            await _repository.UpdateCategory(categoryEntity, token);
                        }
                        else
                        {
                            await _repository.CreateCategory(categoryEntity, token);
                        }
                    }
                }
            }

            Categories.Clear();

            foreach (var category in await _repository.GetCategories(token))
            {
                Categories.Add(new CategoryModel(category, _service));
            }
        }