/// <summary> /// Service Method to add new income record /// </summary> /// <param name="incomeModel"></param> /// <returns>Task Complete</returns> public async Task AddNewIncome(BudgetIncomeModel incomeModel) { //validate income was passed if (incomeModel == null) { throw new ArgumentException("Income not provided"); } //convert core income model to database income entity var dbIncomeEntity = AdoIncomeMapper.CoreModelToDbEntityNew(incomeModel); //add new income await _incomeRepository.AddNewIncome(dbIncomeEntity); }
/// <summary> /// Method to insert / update / remove income records /// </summary> /// <param name="budgetIncomes"></param> /// <returns>Task Complete</returns> public async Task UpsertIncomes(List <BudgetIncomeModel> budgetIncomes) { if (budgetIncomes.Count <= 0) { throw new ArgumentException("Income not provided"); } List <BudgetIncome> dbIncomes = new List <BudgetIncome>(); foreach (var budgetIncome in budgetIncomes) { dbIncomes.Add(AdoIncomeMapper.CoreModelToDbEntityExisting(budgetIncome)); } await _incomeRepository.UpsertIncomes(dbIncomes); }
/// <summary> /// Service method to pull income for specific user by user id /// </summary> /// <param name="userId"></param> /// <returns>List of Budget Income Model objects</returns> public async Task <List <BudgetIncomeModel> > GetAllIncomeByUserId(long userId) { //create empty list of core budget income objects List <BudgetIncomeModel> coreIncomeList = new List <BudgetIncomeModel>(); //pull all income by user id from db var dbIncomeList = await _incomeRepository.GetAllIncomeByUserId(userId); if (dbIncomeList == null) { throw new Exception("Income not found"); } //convert from db income entity to core income model foreach (var income in dbIncomeList) { coreIncomeList.Add(AdoIncomeMapper.DbEntityToCoreModel(income)); } return(coreIncomeList); }