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); }
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); }