Пример #1
0
        public async Task <SavingsGoal> AddSavingsGoal(Guid userId, string name, decimal currentAmount, decimal targetAmount)
        {
            var dataGoal = new Data.Entities.SavingsGoal()
            {
                Name          = name,
                CurrentAmount = currentAmount,
                TargetAmount  = targetAmount,
                UserId        = userId
            };

            // TODO: should wrap in own repository
            Context.SavingsGoals.Add(dataGoal);
            var count = await Context.SaveChangesAsync();

            if (count > 0)
            {
                return(new SavingsGoal
                {
                    Id = dataGoal.Id,
                    UserId = dataGoal.UserId,
                    Name = dataGoal.Name,
                    CurrentAmount = dataGoal.CurrentAmount,
                    TargetAmount = dataGoal.TargetAmount
                });
            }

            return(null);
        }
Пример #2
0
        public async Task <bool> DeleteSavingsGoal(Guid goalId)
        {
            Data.Entities.SavingsGoal goal = new Data.Entities.SavingsGoal()
            {
                Id = goalId
            };

            Context.SavingsGoals.Attach(goal);
            Context.SavingsGoals.Remove(goal);

            var count = await Context.SaveChangesAsync();

            return(count > 0);
        }