Beispiel #1
0
        public async Task <int> AddGoalAsync(GoalModel goalModel)
        {
            goalModel.CheckForNull(nameof(goalModel));

            var goal = _mapper.Map <GoalModel, Goal>(goalModel);

            switch (goal.Type)
            {
            case (byte)GoalTypes.Debt:
            {
                CreateDebtTransaction(goal);
                break;
            }

            case (byte)GoalTypes.Loan:
            {
                CreateLoanTransaction(goal);
                break;
            }
            }

            _context.Goals.Add(goal);
            await _context.SaveChangesAsync();

            return(goal.ID);
        }
Beispiel #2
0
        public void UpdateGoal(GoalModel goalModel)
        {
            goalModel.CheckForNull(nameof(goalModel));

            var goal = _mapper.Map <GoalModel, Goal>(goalModel);

            goal.IsActive = goal.CurrentAmount < goal.TotalAmount ? true : false;

            var goalInDb = _context.Goals.Single(g => g.ID == goal.ID);

            goalInDb.GoalName      = goal.GoalName;
            goalInDb.TotalAmount   = goal.TotalAmount;
            goalInDb.CurrentAmount = goal.CurrentAmount;
            goalInDb.CompleteDate  = goal.CompleteDate;
            goalInDb.IsActive      = goal.IsActive;

            _context.SaveChanges();
        }
Beispiel #3
0
        public void AddGoal(GoalModel goalModel)
        {
            goalModel.CheckForNull(nameof(goalModel));

            var goal = _mapper.Map <GoalModel, Goal>(goalModel);

            switch (goal.Type)
            {
            case (byte)GoalTypes.Debt:
            {
                CreateDebtTransaction(goal);
                break;
            }

            case (byte)GoalTypes.Loan:
            {
                CreateLoanTransaction(goal);
                break;
            }
            }

            _context.Goals.Add(goal);
            _context.SaveChanges();
        }