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); }
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)); }
public async Task <ActionResult <SavingGoal> > Post([FromBody] SavingGoal newSavingGoal) { this.db.SavingGoal.Add(newSavingGoal); await this.db.SaveChangesAsync(); return(newSavingGoal); }
public static void CreateSavingGoal(SavingGoal savingGoal) { using (var db = new BIMFall4Context()) { db.SavingGoals.Add(savingGoal); db.SaveChanges(); } }
private void ValidateSavingGoalDescription(SavingGoal savingGoal, ErrorFound errors) { if (savingGoal.Description == string.Empty) { errors.IsThereAnyError = true; errors.ErrorsFound.Add(Messages.ResourceManager.GetString("SavingGoal_DescriptionError")); } }
private void ValidateSavingGoalNull(SavingGoal savingGoal, ErrorFound errors) { if (savingGoal is null) { errors.IsThereAnyError = true; errors.ErrorsFound.Add(Messages.ResourceManager.GetString("SavingCalculation_SavingGoalNull")); } }
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")); } }
public SavingGoal ConvertSavingGoal(SavingGoalTable savingGoalToConvert) { SavingGoal savingGoalConverted = new SavingGoal { IdSavingGoal = savingGoalToConvert.IdSavingGoal, Description = savingGoalToConvert.Description, MonthlyMovements = ConvertMonthlyMovements(savingGoalToConvert.MonthlyMovements) }; return(savingGoalConverted); }
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); }
// POST: api/SavingGoal public bool Post([FromBody] SavingGoal value) { if (value.Amount > 0) { SavingGoalManager.CreateSavingGoal(value); return(true); } else { return(false); } }
public Response UpdateSavingGoal(SavingGoal savingGoal) { Response response = new Response { ErrorFound = savingGoalValidator.ValidateSavingGoal(savingGoal) }; if (!response.ErrorFound.IsThereAnyError) { savingGoalDataAccess.UpdateSavingGoal(savingGoal); } return(response); }
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(); }
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); } }
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)); }
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); }
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); }
public GoalEditForm(SavingGoal goal, SavingsHelper savingsHelper) { InitializeComponent(); _goal = goal; _savingsHelper = savingsHelper; }
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); }
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); }