コード例 #1
0
        public async Task <IActionResult> AddNewIncome(AddNewIncomeRequest newIncomeRequest)
        {
            if (newIncomeRequest == null)
            {
                return(StatusCode(400, "Income details not provided"));
            }

            try
            {
                BudgetIncomeModel coreIncomeModel = new BudgetIncomeModel()
                {
                    UserId     = (long)newIncomeRequest.UserId,
                    Amount     = (decimal)newIncomeRequest.IncomeAmount,
                    IncomeType = newIncomeRequest.IncomeType
                };

                await _incomeServices.AddNewIncome(coreIncomeModel);

                return(StatusCode(201));
            }
            catch (ArgumentException ae)
            {
                return(StatusCode(400, ae.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        public async Task <IActionResult> UpsertIncomes([FromBody] UpsertIncomesRequest upsertIncomes)
        {
            if (upsertIncomes.Incomes.Count <= 0)
            {
                return(StatusCode(400, "Bad Request"));
            }

            try
            {
                List <BudgetIncomeModel> budgetIncomes = new List <BudgetIncomeModel>();

                foreach (var upsertIncome in upsertIncomes.Incomes)
                {
                    if (upsertIncome.UserId == 0)
                    {
                        return(StatusCode(400, "Bad Request"));
                    }

                    BudgetIncomeModel coreIncomeModel = new BudgetIncomeModel()
                    {
                        Id         = upsertIncome.Id,
                        UserId     = upsertIncome.UserId,
                        Amount     = upsertIncome.Amount,
                        IncomeType = upsertIncome.IncomeType
                    };
                    budgetIncomes.Add(coreIncomeModel);
                }

                await _incomeServices.UpsertIncomes(budgetIncomes);

                return(Ok());
            }
            catch (ArgumentException ae)
            {
                return(StatusCode(400, ae.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }