コード例 #1
0
        public async Task <CategoryModel> SaveCategory(CategoryDto category)
        {
            var categoryModel = new CategoryModel
            {
                name  = category.name,
                color = category.color
            };

            context.Add(categoryModel);
            await context.SaveChangesAsync();

            return(categoryModel);
        }
コード例 #2
0
        public async Task <TransactionModel> SaveTransaction(TransactionDto transaction)
        {
            CategoryModel categoryModel = await context.Category.Where(c => c.id == transaction.categoryId).FirstOrDefaultAsync();

            if (categoryModel == null)
            {
                throw new Exception("Brak kategorii transakcji");
            }
            var transactionModel = new TransactionModel
            {
                title    = transaction.title,
                type     = transaction.type,
                category = categoryModel,
                amount   = transaction.amount
            };

            context.Add(transactionModel);
            await context.SaveChangesAsync();

            return(transactionModel);
        }