예제 #1
0
 public void CreateSavingGoal(SavingGoal model)
 {
     using (var ctx = new OnlineSaverEntities()) {
         ctx.SavingGoals.Add(model);
         ctx.SaveChanges();
     }
 }
        public CalculationResponse GetCurrentAndFutureTransactions(SavingGoal savingGoal, decimal estimatedAmount, decimal savingPerMonth)
        {
            decimal             totalAmount;
            CalculationResponse calculationResponse = new CalculationResponse {
                ErrorFound = savingValidator.ValidateSavingCalculation(savingGoal, estimatedAmount, savingPerMonth)
            };

            if (calculationResponse.ErrorFound.IsThereAnyError)
            {
                return(calculationResponse);
            }

            totalAmount = savingCalculator.GetTotalAmount(savingGoal);
            calculationResponse.ErrorFound = savingValidator.ValidateEstimatedAmount(estimatedAmount, totalAmount);

            if (calculationResponse.ErrorFound.IsThereAnyError)
            {
                return(calculationResponse);
            }

            calculationResponse.Periods = savingCalculator.CreateCurrentAndFutureTransactions(savingGoal.MonthlyMovements,
                                                                                              totalAmount, estimatedAmount, savingPerMonth);

            return(calculationResponse);
        }
예제 #3
0
        public async Task <Guid> Store(SavingGoal goal)
        {
            User       user   = new User();
            HttpClient client = new HttpClient();

            var req = await client.GetAsync("https://localhost:5001/users/parser");

            Task <string> c = req.Content.ReadAsStringAsync();

            var res = JsonConvert.DeserializeObject <List <User> >(c.Result);

            foreach (var g in res)
            {
                if (g.Logged == true)
                {
                    user = new User()
                    {
                        Id        = g.Id,
                        Gmail     = g.Gmail,
                        Card      = g.Card,
                        Cash      = g.Cash,
                        FullName  = g.FullName,
                        UserImage = g.UserImage,
                        Logged    = true,
                        Password  = g.Password
                    };
                }
            }
            goal.UserId = user.Id;
            return(await _savingGoalsRepository.Create(goal));
        }
예제 #4
0
        public async Task <ActionResult <SavingGoal> > Post([FromBody] SavingGoal newSavingGoal)
        {
            this.db.SavingGoal.Add(newSavingGoal);
            await this.db.SaveChangesAsync();

            return(newSavingGoal);
        }
예제 #5
0
 public static void CreateSavingGoal(SavingGoal savingGoal)
 {
     using (var db = new BIMFall4Context())
     {
         db.SavingGoals.Add(savingGoal);
         db.SaveChanges();
     }
 }
예제 #6
0
 private void ValidateSavingGoalDescription(SavingGoal savingGoal, ErrorFound errors)
 {
     if (savingGoal.Description == string.Empty)
     {
         errors.IsThereAnyError = true;
         errors.ErrorsFound.Add(Messages.ResourceManager.GetString("SavingGoal_DescriptionError"));
     }
 }
예제 #7
0
 private void ValidateSavingGoalNull(SavingGoal savingGoal, ErrorFound errors)
 {
     if (savingGoal is null)
     {
         errors.IsThereAnyError = true;
         errors.ErrorsFound.Add(Messages.ResourceManager.GetString("SavingCalculation_SavingGoalNull"));
     }
 }
예제 #8
0
 private void ValidateSavingGoalAmountSaved(SavingGoal savingGoal, ErrorFound errors)
 {
     if (savingGoal.MonthlyMovements[0].SavedAmount < decimal.Zero)
     {
         errors.IsThereAnyError = true;
         errors.ErrorsFound.Add(Messages.ResourceManager.GetString("SavingGoal_AmountSavedError"));
     }
 }
예제 #9
0
        public SavingGoal ConvertSavingGoal(SavingGoalTable savingGoalToConvert)
        {
            SavingGoal savingGoalConverted = new SavingGoal {
                IdSavingGoal     = savingGoalToConvert.IdSavingGoal,
                Description      = savingGoalToConvert.Description,
                MonthlyMovements = ConvertMonthlyMovements(savingGoalToConvert.MonthlyMovements)
            };

            return(savingGoalConverted);
        }
예제 #10
0
        public ErrorFound ValidateSavingCalculation(SavingGoal savingGoal, decimal estimatedAmount, decimal savingPerMonth)
        {
            ErrorFound errors = new ErrorFound();

            ValidateSavingGoalNull(savingGoal, errors);
            ValidateMonthlyMovementsNull(savingGoal.MonthlyMovements, errors);
            ValidateAmount(estimatedAmount, errors);
            ValidateSavingPerMonth(savingPerMonth, errors);

            return(errors);
        }
        public decimal GetTotalAmount(SavingGoal savingGoal)
        {
            decimal totalAmount = decimal.Zero;

            foreach (MonthlyMovement monthlyMovement in savingGoal.MonthlyMovements)
            {
                totalAmount += monthlyMovement.SavedAmount;
            }

            return(totalAmount);
        }
예제 #12
0
 // POST: api/SavingGoal
 public bool Post([FromBody] SavingGoal value)
 {
     if (value.Amount > 0)
     {
         SavingGoalManager.CreateSavingGoal(value);
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #13
0
        public Response UpdateSavingGoal(SavingGoal savingGoal)
        {
            Response response = new Response {
                ErrorFound = savingGoalValidator.ValidateSavingGoal(savingGoal)
            };

            if (!response.ErrorFound.IsThereAnyError)
            {
                savingGoalDataAccess.UpdateSavingGoal(savingGoal);
            }

            return(response);
        }
예제 #14
0
        private void addGoalButton_Click(object sender, EventArgs e)
        {
            bool   successfulAmountParse = false;
            double goalAmount;
            string parseMessage = SavingsHelper.AmountValidator(goalAmountTextBox.Text, out successfulAmountParse, out goalAmount);

            if (successfulAmountParse == false)
            {
                Error.ShowDialog(parseMessage);
                return;
            }

            bool   successfulDateValidation = false;
            string dateValidationMessage    = SavingsHelper.GoalDateValidator(endDateCalendar.SelectionStart, out successfulDateValidation);

            if (successfulDateValidation == false)
            {
                Error.ShowDialog(dateValidationMessage);
                return;
            }

            if (string.IsNullOrEmpty(goalNameTextBox.Text))
            {
                MessageBox.Show("Please provide a name for your goal.");
                return;
            }
            else if (string.IsNullOrEmpty(goalAmountTextBox.Text))
            {
                MessageBox.Show("Please provide an amount you want to reach for your goal.");
            }


            SavingGoal goal = new SavingGoal()
            {
                GoalName    = goalNameTextBox.Text,
                Description = goalDescriptionTextBox.Text,
                GoalAmount  = goalAmount,
                StartDate   = DateTime.Now,
                FinishDate  = endDateCalendar.SelectionStart,
                UserId      = Domain.Constants.Constants.TestUserId,
            };

            SendGoalToDB(goal);
            ResetTextBoxValues();
            Hide();
        }
예제 #15
0
        public async void AddOrUpdateGoalToDB(SavingGoal goal)
        {
            var tempGoal = await _savingsRepository.GetUserGoalIfExists(goal);

            if (goal.Progress >= goal.GoalAmount)
            {
                //Goal Completed
                return;
            }
            if (tempGoal != null)
            {
                await _savingsRepository.Update(goal.Id, goal);
            }
            else
            {
                await _savingsRepository.Create(goal);
            }
        }
예제 #16
0
 public ActionResult CreateGoal(GoalViewModel model)
 {
     if (ModelState.IsValid)
     {
         var newGoal = new SavingGoal()
         {
             Description = model.Description,
             CreateDate  = DateTime.Now,
             SavedAmount = 0,
             Title       = model.Title,
             Goal        = model.SaveGoal,
             UserId      = User.Identity.GetUserId()
         };
         savingGoalService.CreateSavingGoal(newGoal);
         TempData["GoalCreated"] = true;
         return(RedirectToAction("Index", "Home"));
     }
     return(View("Index", model));
 }
예제 #17
0
        public ErrorFound ValidateSavingGoal(SavingGoal savingGoal)
        {
            ErrorFound errors = new ErrorFound();

            ValidateSavingGoalNull(savingGoal, errors);
            if (errors.IsThereAnyError)
            {
                return(errors);
            }
            ValidateSavingGoalDescription(savingGoal, errors);
            ValidateMonthlyMovementsNull(savingGoal.MonthlyMovements, errors);
            if (errors.IsThereAnyError)
            {
                return(errors);
            }
            ValidateMonthlyMovements(savingGoal.MonthlyMovements, errors);
            ValidateSavingGoalAmountSaved(savingGoal, errors);

            return(errors);
        }
예제 #18
0
        public static SavingGoal[] GenerateMockData()
        {
            Guid guid = new Guid("6e33fa08-bc0f-438c-a21b-bcf4fc227661");

            SavingGoal[] goals = new SavingGoal[3];
            goals[0] = new SavingGoal
            {
                GoalName    = "test1",
                Description = "testing",
                GoalAmount  = 100.48,
                StartDate   = DateTime.Now,
                FinishDate  = DateTime.Today.AddDays(1),
                Progress    = 0.48,
                UserId      = guid
            };
            goals[1] = new SavingGoal
            {
                GoalName    = "test2",
                Description = "testing",
                GoalAmount  = 500,
                StartDate   = DateTime.Now,
                FinishDate  = DateTime.Today.AddDays(3),
                Progress    = 120,
                UserId      = guid
            };
            goals[2] = new SavingGoal
            {
                GoalName    = "test3",
                Description = "testing",
                GoalAmount  = 420,
                StartDate   = DateTime.Now,
                FinishDate  = DateTime.Today.AddDays(7),
                Progress    = 300,
                UserId      = guid
            };
            return(goals);
        }
예제 #19
0
 public GoalEditForm(SavingGoal goal, SavingsHelper savingsHelper)
 {
     InitializeComponent();
     _goal          = goal;
     _savingsHelper = savingsHelper;
 }
예제 #20
0
 private void SendGoalToDB(SavingGoal goal)
 {
     _savingsHelper.AddOrUpdateGoalToDB(goal);
 }
 public async Task<Guid> Store(SavingGoal goal)
 {
     goal.UserId = Domain.Constants.Constants.TestUserId;
     return await _savingGoalsRepository.Create(goal);
 }
예제 #22
0
 public async void Update(SavingGoal goal)
 {
     await _savingGoalsRepository.Update(goal.Id, goal);
 }
        public Response UpdateSavingGoal([FromServices] ISavingGoalDataAccess savingGoalDataAccess, [FromQuery] SavingGoal savingGoal)
        {
            Response response;

            SavingGoalFlow savingGoalFlow = new SavingGoalFlow(savingGoalDataAccess);

            response = savingGoalFlow.UpdateSavingGoal(savingGoal);

            return(response);
        }