public async Task <Group> CreateGroupAsync(Group group) { _context.Groups.Add(group); await _context.SaveChangesAsync(); return(group); }
public async Task <Balance> Add(Balance newBalance) { try { if (newBalance != null) { newBalance.Month = await GetMonth(newBalance.MonthId); newBalance.TotalIncomes = 0; newBalance.TotalSpendings = 0; newBalance.BalanceResult = 0; _context.Add(newBalance); await _context.SaveChangesAsync(); return(newBalance); } return(null); } catch (Exception) { return(null); } }
public async Task <Report> CreateReportAsync(Report report) { _context.Reports.Add(report); await _context.SaveChangesAsync(); return(report); }
public async Task <Expense> CreateExpenseAsync(Expense expense) { _context.Expenses.Add(expense); await _context.SaveChangesAsync(); return(await _context.Expenses .Include(e => e.Category) .Include(e => e.User) .Include(e => e.Report) .SingleOrDefaultAsync(e => e.Id == expense.Id)); }
public async Task <IActionResult> Create([Bind("Id,CategoryName")] EIncomeType eIncomeType) { if (ModelState.IsValid) { _context.Add(eIncomeType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(eIncomeType)); }
public async Task <Category> CreateCategoryAsync(Category category) { if (_context.Categories.Any(c => c.Name == category.Name)) { throw new EntityAlreadyExistsException($"Category '{category.Name}' already exists."); } _context.Categories.Add(category); await _context.SaveChangesAsync(); return(category); }
public async Task <User> CreateUserAsync(User user, string password) { if (string.IsNullOrWhiteSpace(password)) { throw new ArgumentException("Value cannot be null or empty.", "password"); } if (_context.Users.Any(u => u.Name == user.Name)) { throw new EntityAlreadyExistsException($"Username '{user.Name}' is already taken."); } UpdateUserPassword(ref user, password); _context.Users.Add(user); await _context.SaveChangesAsync(); return(user); }
public async Task <(User user, Group group)> CreateUserGroupAsync(int userId, int groupId) { var(user, group) = await GetUserAndGroupAsync(userId, groupId); if (!user.UserGroups.Any(ug => ug.User == user && ug.Group == group)) { var ug = new UserGroup { User = user, Group = group, }; user.UserGroups.Add(ug); _context.Users.Update(user); await _context.SaveChangesAsync(); } return(user, group); }
public async Task <AnualBalance> Add(AnualBalance entity) { try { if (entity != null) { entity.AnualBalanceResult = 0; _context.Add(entity); await _context.SaveChangesAsync(); return(entity); } return(null); } catch (Exception) { return(null); } }
public async Task <ShoppingList> CreateShoppingListAsync(ShoppingList shoppingList) { _context.ShoppingLists.Add(shoppingList); await _context.SaveChangesAsync(); return(shoppingList); }
public async Task <Spending> Add(Spending entity) { try { if (entity != null) { _context.Add(entity); await _context.SaveChangesAsync(); if (await _balanceRepo.CalculateAndSave(await GetParentBalance(entity.Id)) != null) { return(entity); } return(null); } return(null); } catch (Exception) { throw null; } }
public async Task <Income> Add(Income income) { try { if (income != null) { _context.Add(income); await _context.SaveChangesAsync(); if (await _balanceRepo.CalculateAndSave(await GetParentBalance(income.Id)) != null) { return(income); } return(null); } return(null); } catch (Exception) { throw null; } }