示例#1
0
        public async Task <IActionResult> CreateCategory([FromBody] CategoryViewModel model)
        {
            int          collocId = model.CollocId;
            Result <int> result   = await _categoryGateway.CreateCategory(model.CategoryName, model.IconName, collocId);

            return(this.CreateResult(result, o =>
            {
                o.RouteName = "GetCategory";
                o.RouteValues = categoryId => new { categoryId };
            }));
        }
示例#2
0
        public async Task can_create_find_update_delete_a_budget()
        {
            BudgetGateway sut = new BudgetGateway(TestHelpers.ConnectionString);

            int      categoryId = 0;
            DateTime date1      = TestHelpers.RandomBirthDate(1);
            DateTime date2      = TestHelpers.RandomBirthDate(2);
            int      amount     = 50;
            int      collocId   = 0;

            Result <int> budgetResult = await sut.CreateBudget(categoryId, date1, date2, amount);

            Assert.That(budgetResult.Status, Is.EqualTo(Status.Created));

            int budgetId = budgetResult.Content;

            Result <BudgetData> budgetData;
            {
                budgetData = await sut.FindBudgetById(budgetId);

                checkBudget(budgetData, categoryId, date1, date2, amount, collocId);
            }
            {
                CategoryGateway categoryGateway = new CategoryGateway(TestHelpers.ConnectionString);
                Result <int>    result          = await categoryGateway.CreateCategory(TestHelpers.RandomTestName(), TestHelpers.RandomTestName(), 0);

                categoryId = result.Content;
                CollocGateway collocGateway = new CollocGateway(TestHelpers.ConnectionString);
                Result <int>  result1       = await collocGateway.CreateColloc(TestHelpers.RandomTestName(), 0);

                collocId = result.Content;
                amount   = 100;
                date1    = TestHelpers.RandomBirthDate(2);
                date2    = TestHelpers.RandomBirthDate(3);
                await sut.UpdateBudget(budgetId, categoryId, date1, date2, amount, collocId);

                budgetData = await sut.FindBudgetById(budgetId);

                checkBudget(budgetData, categoryId, date1, date2, amount, collocId);
            }
            {
                Result r = await sut.DeleteBudget(budgetId);

                Assert.That(r.Status, Is.EqualTo(Status.Ok));

                budgetData = await sut.FindBudgetById(budgetId);

                Assert.That(budgetData.Status, Is.EqualTo(Status.NotFound));
            }
        }
示例#3
0
        protected async Task HandleSubmit()
        {
            if (!EditContext.Validate())
            {
                return;
            }

            if (MicroId == Guid.Empty)
            {
                await CategoryGateway.CreateCategory(Category);
            }
            else
            {
                await CategoryGateway.UpdateCategory(MicroId, Category);
            }

            NavigationManager.NavigateTo("/categories");
        }
示例#4
0
        public async Task can_create_find_update_delete_category()
        {
            CategoryGateway sut = new CategoryGateway(TestHelpers.ConnectionString);

            string categoryName = TestHelpers.RandomTestName();
            string icon         = TestHelpers.RandomTestName();
            int    collocId     = 0;

            Result <int> categoryResult = await sut.CreateCategory(categoryName, icon, collocId);

            Assert.That(categoryResult.Status, Is.EqualTo(Status.Created));

            int categoryId = categoryResult.Content;

            Result <CategoryData> categoryData;
            {
                categoryData = await sut.FindCategoryId(categoryId);

                CheckCategory(categoryData, categoryName, icon, collocId);
            }
            {
                categoryName = TestHelpers.RandomTestName();
                icon         = TestHelpers.RandomTestName();
                CollocGateway coGateway = new CollocGateway(TestHelpers.ConnectionString);
                var           colloc    = await coGateway.CreateColloc(TestHelpers.RandomTestName(), 0);

                collocId = colloc.Content;
                await sut.UpdateCategory(categoryId, categoryName, icon, collocId);

                categoryData = await sut.FindCategoryId(categoryId);

                CheckCategory(categoryData, categoryName, icon, collocId);
            }

            {
                Result r = await sut.DeleteCategory(categoryId);

                Assert.That(r.Status, Is.EqualTo(Status.Ok));

                categoryData = await sut.FindCategoryId(categoryId);

                Assert.That(categoryData.Status, Is.EqualTo(Status.NotFound));
            }
        }