/// <summary> /// Creates an PaymentViewModel based on the recurring PaymentViewModel. /// </summary> /// <param name="recurringPayment">The recurring PaymentViewModel the new PaymentViewModel shall be based on.</param> /// <returns>The new created PaymentViewModel</returns> public static PaymentViewModel GetPaymentFromRecurring(RecurringPaymentViewModel recurringPayment) { var date = DateTime.Today; //If the PaymentViewModel is monthly we want it on the same day of month again. if (recurringPayment.Recurrence == PaymentRecurrence.Monthly) { date = DateTime.Today.AddDays(recurringPayment.StartDate.Day - DateTime.Today.Day); } return new PaymentViewModel { ChargedAccount = recurringPayment.ChargedAccount, ChargedAccountId = recurringPayment.ChargedAccountId, TargetAccount = recurringPayment.TargetAccount, TargetAccountId = recurringPayment.TargetAccountId, Date = date, IsRecurring = true, Amount = recurringPayment.Amount, Category = recurringPayment.Category, CategoryId = recurringPayment.CategoryId, Type = recurringPayment.Type, RecurringPaymentId = recurringPayment.Id, RecurringPayment = recurringPayment, Note = recurringPayment.Note }; }
// GET: RecurringPayments/Details/5 public async Task <IActionResult> Details(string id) { if (id == null) { return(NotFound()); } var recurringPayment = dataLayer.GetUserRecurringPayment(ApplicationUser, id); if (recurringPayment == null) { return(NotFound()); } var categories = dataLayer.GetUserCategories(ApplicationUser).OrderByDescending(c => c.IsDefault); var intervals = dataLayer.GetIntervals().OrderByDescending(c => c.IsDefault); var paymentTypes = dataLayer.GetUserPaymentTypes(ApplicationUser).OrderByDescending(c => c.IsDefault); dataLayer.Load(recurringPayment, rp => rp.Category); dataLayer.Load(recurringPayment, rp => rp.Interval); dataLayer.Load(recurringPayment, rp => rp.PaymentType); var recurringPaymentVM = new RecurringPaymentViewModel(); ModelToVm(recurringPayment, recurringPaymentVM, intervals.ToList()); return(View(recurringPaymentVM)); }
/// <summary> /// Creates an PaymentViewModel based on the recurring PaymentViewModel. /// </summary> /// <param name="recurringPayment">The recurring PaymentViewModel the new PaymentViewModel shall be based on.</param> /// <returns>The new created PaymentViewModel</returns> public static PaymentViewModel GetPaymentFromRecurring(RecurringPaymentViewModel recurringPayment) { var date = DateTime.Today; //If the PaymentViewModel is monthly we want it on the same day of month again. if (recurringPayment.Recurrence == PaymentRecurrence.Monthly) { date = DateTime.Today.AddDays(recurringPayment.StartDate.Day - DateTime.Today.Day); } return(new PaymentViewModel { ChargedAccount = recurringPayment.ChargedAccount, ChargedAccountId = recurringPayment.ChargedAccountId, TargetAccount = recurringPayment.TargetAccount, TargetAccountId = recurringPayment.TargetAccountId, Date = date, IsRecurring = true, Amount = recurringPayment.Amount, Category = recurringPayment.Category, CategoryId = recurringPayment.CategoryId, Type = recurringPayment.Type, RecurringPaymentId = recurringPayment.Id, RecurringPayment = recurringPayment, Note = recurringPayment.Note }); }
// GET: RecurringPayments/Edit/5 public async Task <IActionResult> Edit(string id) { if (id == null) { return(NotFound()); } var recurringPayment = dataLayer.GetUserRecurringPayment(ApplicationUser, id); if (recurringPayment == null) { return(NotFound()); } var categories = dataLayer.GetUserCategories(ApplicationUser).OrderByDescending(c => c.IsDefault); var intervals = dataLayer.GetIntervals().OrderByDescending(c => c.IsDefault); var paymentTypes = dataLayer.GetUserPaymentTypes(ApplicationUser).OrderByDescending(c => c.IsDefault); ViewBag.CategoryId = new SelectList(categories, $"{nameof(Category.Id)}", $"{nameof(Category.Description)}", recurringPayment.CategoryId); ViewBag.IntervalId = new SelectList(intervals, $"{nameof(Interval.Id)}", $"{nameof(Interval.Description)}", recurringPayment.IntervalId); ViewBag.PaymentTypeId = new SelectList(paymentTypes, $"{nameof(PaymentType.Id)}", $"{nameof(PaymentType.Description)}", recurringPayment.PaymentTypeId); var recurringPaymentVM = new RecurringPaymentViewModel(); ModelToVm(recurringPayment, recurringPaymentVM, intervals.ToList()); return(View(recurringPaymentVM)); }
public async Task <IActionResult> GeneratePayment(string id) { if (id == null) { return(NotFound()); } var recurringPayment = dataLayer.GetUserRecurringPayment(ApplicationUser, id); if (recurringPayment == null) { return(NotFound()); } var categories = dataLayer.GetUserCategories(ApplicationUser).OrderByDescending(c => c.IsDefault); var intervals = dataLayer.GetIntervals().OrderByDescending(c => c.IsDefault); var paymentTypes = dataLayer.GetUserPaymentTypes(ApplicationUser).OrderByDescending(c => c.IsDefault); ViewBag.CategoryId = new SelectList(categories, $"{nameof(Category.Id)}", $"{nameof(Category.Description)}", recurringPayment.CategoryId); ViewBag.IntervalId = new SelectList(intervals, $"{nameof(Interval.Id)}", $"{nameof(Interval.Description)}", recurringPayment.IntervalId); ViewBag.PaymentTypeId = new SelectList(paymentTypes, $"{nameof(PaymentType.Id)}", $"{nameof(PaymentType.Description)}", recurringPayment.PaymentTypeId); var recurringPaymentVM = new RecurringPaymentViewModel(); ModelToVm(recurringPayment, recurringPaymentVM, intervals.ToList()); var record = new TwaWallet.Model.Record { ApplicationUser = await userManager.GetUserAsync(User), CategoryId = recurringPayment.CategoryId, Cost = recurringPayment.Cost, Date = DateTime.Now, Description = recurringPayment.Description, Earnings = recurringPayment.Earnings, PaymentTypeId = recurringPayment.PaymentTypeId, Tag = recurringPayment.Tag, Warranty = recurringPayment.Warranty }; await dataLayer.AddAsync(record); return(RedirectToAction(nameof(Index))); //return RedirectToAction(nameof(Index), "Records"); //return RedirectToAction("Create", "Records", new TwaWallet.Model.Record //{ // //ApplicationUserId = Model.apli, // CategoryId = recurringPayment.CategoryId, // Cost = recurringPayment.Cost, // Date = DateTime.Now.AddDays(-2), // Description = recurringPayment.Description, // Earnings = recurringPayment.Earnings, // PaymentTypeId = recurringPayment.PaymentTypeId, // Tag = recurringPayment.Tag, // Warranty = recurringPayment.Warranty //}); //return new RecordsController(userManager, dataLayer).SetCreate(record); //return View(recurringPaymentVM); }
/// <summary> /// Deletes the passed RecurringPaymentViewModel and removes it from cache /// </summary> public bool Delete(RecurringPaymentViewModel paymentTodelete) { using (var db = dbManager.GetConnection()) { var itemToDelete = db.Table <RecurringPayment>().Single(x => x.Id == paymentTodelete.Id); return(db.Delete(itemToDelete) == 1); } }
/// <summary> /// Deletes the passed RecurringPaymentViewModel and removes it from cache /// </summary> public bool Delete(RecurringPaymentViewModel paymentTodelete) { using (var db = dbManager.GetConnection()) { var itemToDelete = db.Table<RecurringPayment>().Single(x => x.Id == paymentTodelete.Id); return db.Delete(itemToDelete) == 1; } }
public void Ctor_SetDefaults() { // Arrange // Act var vm = new RecurringPaymentViewModel(); // Assert vm.Recurrence.ShouldEqual(PaymentRecurrence.Daily); vm.EndDate.Value.Date.ShouldEqual(DateTime.Today); }
public void Category_SetId() { var paymentVm = new RecurringPaymentViewModel(); paymentVm.Category.ShouldBeNull(); paymentVm.CategoryId.ShouldBeNull(); var category = new Fixture().Create<CategoryViewModel>(); paymentVm.Category = category; paymentVm.Category.ShouldBe(category); paymentVm.Category.Id.ShouldBe(category.Id); paymentVm.CategoryId.ShouldBe(category.Id); }
public void TargetAccount_SetId() { var paymentVm = new RecurringPaymentViewModel(); paymentVm.TargetAccount.ShouldBeNull(); paymentVm.TargetAccountId.ShouldBe(0); var accountViewModel = new Fixture().Create<AccountViewModel>(); paymentVm.TargetAccount = accountViewModel; paymentVm.TargetAccount.ShouldBe(accountViewModel); paymentVm.TargetAccount.Id.ShouldBe(accountViewModel.Id); paymentVm.TargetAccountId.ShouldBe(accountViewModel.Id); }
public void Category_SetId() { var paymentVm = new RecurringPaymentViewModel(); paymentVm.Category.ShouldBeNull(); paymentVm.CategoryId.ShouldBeNull(); var category = new Fixture().Create <CategoryViewModel>(); paymentVm.Category = category; paymentVm.Category.ShouldBe(category); paymentVm.Category.Id.ShouldBe(category.Id); paymentVm.CategoryId.ShouldBe(category.Id); }
private void VmToModel(RecurringPaymentViewModel recurringPaymentVM, RecurringPayment recurringPayment, List <Interval> intervals) { recurringPayment.ApplicationUser = ApplicationUser; recurringPayment.CategoryId = recurringPaymentVM.CategoryId; recurringPayment.Cost = recurringPaymentVM.Cost; recurringPayment.Description = recurringPaymentVM.Description; recurringPayment.Earnings = recurringPaymentVM.Earnings; recurringPayment.EndDate = recurringPaymentVM.EndDate; recurringPayment.IntervalId = recurringPaymentVM.IntervalId; recurringPayment.IsActive = recurringPaymentVM.IsActive; recurringPayment.PaymentTypeId = recurringPaymentVM.PaymentTypeId; recurringPayment.LastUpdate = intervals.Single(i => i.Id == recurringPaymentVM.IntervalId).BeforeDateTime(recurringPaymentVM.NextDate); recurringPayment.Tag = recurringPaymentVM.Tag; recurringPayment.Warranty = recurringPaymentVM.Warranty; }
public void TargetAccount_SetId() { var paymentVm = new RecurringPaymentViewModel(); paymentVm.TargetAccount.ShouldBeNull(); paymentVm.TargetAccountId.ShouldBe(0); var accountViewModel = new Fixture().Create <AccountViewModel>(); paymentVm.TargetAccount = accountViewModel; paymentVm.TargetAccount.ShouldBe(accountViewModel); paymentVm.TargetAccount.Id.ShouldBe(accountViewModel.Id); paymentVm.TargetAccountId.ShouldBe(accountViewModel.Id); }
public void EnumToTypeInt_CorrectlyParsed(PaymentType type, int enumInt) { var cb = new ContainerBuilder(); cb.RegisterModule<DataAccessModule>(); cb.Build(); var paymentViewModel = new RecurringPaymentViewModel() { Id = 9, Type = type }; var mappedPayment = Mapper.Map<RecurringPayment>(paymentViewModel); mappedPayment.Type.ShouldBe(enumInt); }
/// <summary> /// Save a new RecurringPaymentViewModel or update an existing one. /// </summary> public bool Save(RecurringPaymentViewModel paymentVmToSave) { using (var db = dbManager.GetConnection()) { var recurringPayment = Mapper.Map<RecurringPayment>(paymentVmToSave); if (recurringPayment.Id == 0) { var rows = db.Insert(recurringPayment); paymentVmToSave.Id = db.Table<RecurringPayment>().OrderByDescending(x => x.Id).First().Id; return rows == 1; } return db.Update(recurringPayment) == 1; } }
/// <summary> /// Save a new RecurringPaymentViewModel or update an existing one. /// </summary> public bool Save(RecurringPaymentViewModel paymentVmToSave) { using (var db = dbManager.GetConnection()) { var recurringPayment = Mapper.Map <RecurringPayment>(paymentVmToSave); if (recurringPayment.Id == 0) { var rows = db.Insert(recurringPayment); paymentVmToSave.Id = db.Table <RecurringPayment>().OrderByDescending(x => x.Id).First().Id; return(rows == 1); } return(db.Update(recurringPayment) == 1); } }
public void EnumToRecurrenceInt_CorrectlyParsed(PaymentRecurrence type, int enumInt) { var cb = new ContainerBuilder(); cb.RegisterModule <DataAccessModule>(); cb.Build(); var paymentViewModel = new RecurringPaymentViewModel { Id = 9, Recurrence = type }; var mappedPayment = Mapper.Map <RecurringPayment>(paymentViewModel); mappedPayment.Recurrence.ShouldBe(enumInt); }
/// <summary> /// Save a new RecurringPaymentViewModel or update an existing one. /// </summary> public bool Save(RecurringPaymentViewModel paymentVmToSave) { using (var db = dbManager.GetConnection()) { var recurringPayment = Mapper.Map <RecurringPayment>(paymentVmToSave); //We have to map the category ID manually, otherwise it won't be set when compiled with .net native. recurringPayment.CategoryId = paymentVmToSave.CategoryId; if (recurringPayment.Id == 0) { var rows = db.Insert(recurringPayment); paymentVmToSave.Id = db.Table <RecurringPayment>().OrderByDescending(x => x.Id).First().Id; return(rows == 1); } return(db.Update(recurringPayment) == 1); } }
// GET: RecurringPayments/Create public IActionResult Create() { var categories = dataLayer.GetUserCategories(ApplicationUser).OrderByDescending(c => c.IsDefault); var intervals = dataLayer.GetIntervals().OrderByDescending(c => c.IsDefault); var paymentTypes = dataLayer.GetUserPaymentTypes(ApplicationUser).OrderByDescending(c => c.IsDefault); ViewBag.CategoryId = new SelectList(categories, $"{nameof(Category.Id)}", $"{nameof(Category.Description)}"); ViewBag.IntervalId = new SelectList(intervals, $"{nameof(Interval.Id)}", $"{nameof(Interval.Description)}"); ViewBag.PaymentTypeId = new SelectList(paymentTypes, $"{nameof(PaymentType.Id)}", $"{nameof(PaymentType.Description)}"); // alternativa //ViewData["CategoryId"] = new SelectList(_dataLayer.GetUserCategories().OrderByDescending(c => c.IsDefault), $"{nameof(Category.Id)}", $"{nameof(Category.Description)}"); //ViewBag.PaymentTypeId = new SelectList(dataLayer.GetUserPaymentTypes().OrderByDescending(p => p.IsDefault), $"{nameof(PaymentType.Id)}", $"{nameof(PaymentType.Description)}"); ViewBag.Date = DateTime.Now; var recurringPaymentVM = new RecurringPaymentViewModel(); return(View(recurringPaymentVM)); }
public void RemoveRecurringForPayments(RecurringPaymentViewModel recurringPayment) { try { var relatedPayment = paymentRepository .Data .Where(x => x.IsRecurring && x.RecurringPayment.Id == recurringPayment.Id); foreach (var payment in relatedPayment) { payment.IsRecurring = false; payment.RecurringPayment.Id = 0; paymentRepository.Save(payment); } } catch (Exception ex) { new TelemetryClient().TrackException(ex); } }
public void CheckIfRepeatable_UnclearedPayment_ReturnFalse(PaymentRecurrence recurrence, int amountOfDaysUntilRepeat) { var account = new AccountViewModel { Id = 2 }; var recurringPayment = new RecurringPaymentViewModel { Id = 4, Recurrence = PaymentRecurrence.Weekly, StartDate = new DateTime(2015, 08, 25), ChargedAccountId = 2, ChargedAccount = account, Amount = 105 }; RecurringPaymentHelper.CheckIfRepeatable(recurringPayment, new PaymentViewModel { Date = DateTime.Today.AddDays(amountOfDaysUntilRepeat) }).ShouldBeFalse(); }
//public async Task<IActionResult> Edit(string id, [Bind("Description,CategoryId,PaymentTypeId,ApplicationUserId,Cost,IntervalId,Earnings,Warranty,Tag,DateCreated,LastUpdate,IsActive,EndDate,Id")] RecurringPayment recurringPayment) public async Task <IActionResult> Edit(string id, [Bind("Description,CategoryId,PaymentTypeId,ApplicationUserId,Cost,IntervalId,Earnings,Warranty,Tag,IsActive,StartDate,EndDate,Id")] RecurringPaymentViewModel recurringPaymentVM) { if (id != recurringPaymentVM.Id) { return(NotFound()); } var categories = dataLayer.GetUserCategories(ApplicationUser).OrderByDescending(c => c.IsDefault); var intervals = dataLayer.GetIntervals().OrderByDescending(c => c.IsDefault); var paymentTypes = dataLayer.GetUserPaymentTypes(ApplicationUser).OrderByDescending(c => c.IsDefault); if (ModelState.IsValid) { try { var recurringPayment = dataLayer.GetUserRecurringPayment(ApplicationUser, recurringPaymentVM.Id); VmToModel(recurringPaymentVM, recurringPayment, intervals.ToList()); await dataLayer.UpdateAsync(recurringPayment); } catch (DbUpdateConcurrencyException) { if (!RecurringPaymentExists(recurringPaymentVM.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewBag.CategoryId = new SelectList(categories, $"{nameof(Category.Id)}", $"{nameof(Category.Description)}", recurringPaymentVM.CategoryId); ViewBag.IntervalId = new SelectList(intervals, $"{nameof(Interval.Id)}", $"{nameof(Interval.Description)}", recurringPaymentVM.IntervalId); ViewBag.PaymentTypeId = new SelectList(paymentTypes, $"{nameof(PaymentType.Id)}", $"{nameof(PaymentType.Description)}", recurringPaymentVM.PaymentTypeId); return(View(recurringPaymentVM)); }
/// <summary> /// Checks if the recurring PaymentViewModel is up for a repetition based on the passed PaymentViewModel /// </summary> /// <param name="recurringPayment">Recurring PaymentViewModel to check.</param> /// <param name="relatedPayment">PaymentViewModel to compare.</param> /// <returns>True or False if the PaymentViewModel have to be repeated.</returns> public static bool CheckIfRepeatable(RecurringPaymentViewModel recurringPayment, PaymentViewModel relatedPayment) { if (!relatedPayment.IsCleared) { return(false); } switch (recurringPayment.Recurrence) { case PaymentRecurrence.Daily: return(DateTime.Today.Date != relatedPayment.Date.Date); case PaymentRecurrence.DailyWithoutWeekend: return((DateTime.Today.Date != relatedPayment.Date.Date) && (DateTime.Today.DayOfWeek != DayOfWeek.Saturday) && (DateTime.Today.DayOfWeek != DayOfWeek.Sunday)); case PaymentRecurrence.Weekly: var daysWeekly = DateTime.Now - relatedPayment.Date; return(daysWeekly.Days >= 7); case PaymentRecurrence.Biweekly: var daysBiweekly = DateTime.Now - relatedPayment.Date; return(daysBiweekly.Days >= 14); case PaymentRecurrence.Monthly: return(DateTime.Now.Month != relatedPayment.Date.Month); case PaymentRecurrence.Bimonthly: return(relatedPayment.Date.Month <= DateTime.Now.AddMonths(-2).Month); case PaymentRecurrence.Yearly: return(((DateTime.Now.Year != relatedPayment.Date.Year) && (DateTime.Now.Month >= relatedPayment.Date.Month)) || (DateTime.Now.Year - relatedPayment.Date.Year > 1)); default: return(false); } }
/// <summary> /// Checks if the recurring PaymentViewModel is up for a repetition based on the passed PaymentViewModel /// </summary> /// <param name="recurringPayment">Recurring PaymentViewModel to check.</param> /// <param name="relatedPayment">PaymentViewModel to compare.</param> /// <returns>True or False if the PaymentViewModel have to be repeated.</returns> public static bool CheckIfRepeatable(RecurringPaymentViewModel recurringPayment, PaymentViewModel relatedPayment) { if (!relatedPayment.IsCleared) { return false; } switch (recurringPayment.Recurrence) { case PaymentRecurrence.Daily: return DateTime.Today.Date != relatedPayment.Date.Date; case PaymentRecurrence.DailyWithoutWeekend: return (DateTime.Today.Date != relatedPayment.Date.Date) && (DateTime.Today.DayOfWeek != DayOfWeek.Saturday) && (DateTime.Today.DayOfWeek != DayOfWeek.Sunday); case PaymentRecurrence.Weekly: var daysWeekly = DateTime.Now - relatedPayment.Date; return daysWeekly.Days >= 7; case PaymentRecurrence.Biweekly: var daysBiweekly = DateTime.Now - relatedPayment.Date; return daysBiweekly.Days >= 14; case PaymentRecurrence.Monthly: return DateTime.Now.Month != relatedPayment.Date.Month; case PaymentRecurrence.Bimonthly: return relatedPayment.Date.Month <= DateTime.Now.AddMonths(-2).Month; case PaymentRecurrence.Yearly: return ((DateTime.Now.Year != relatedPayment.Date.Year) && (DateTime.Now.Month >= relatedPayment.Date.Month)) || (DateTime.Now.Year - relatedPayment.Date.Year > 1); default: return false; } }
//public async Task<IActionResult> Create([Bind("Description,CategoryId,PaymentTypeId,ApplicationUserId,Cost,IntervalId,Earnings,Warranty,Tag,DateCreated,LastUpdate,IsActive,EndDate,Id")] RecurringPayment recurringPayment) public async Task <IActionResult> Create([Bind("Description,CategoryId,PaymentTypeId,Cost,IntervalId,Earnings,Warranty,Tag,IsActive,StartDate,EndDate")] RecurringPaymentViewModel recurringPaymentVM) { var categories = dataLayer.GetUserCategories(ApplicationUser).OrderByDescending(c => c.IsDefault); var intervals = dataLayer.GetIntervals().OrderByDescending(c => c.IsDefault); var paymentTypes = dataLayer.GetUserPaymentTypes(ApplicationUser).OrderByDescending(c => c.IsDefault); if (ModelState.IsValid) { var recurringPayment = new RecurringPayment(); VmToModel(recurringPaymentVM, recurringPayment, intervals.ToList()); await dataLayer.AddAsync(recurringPayment); return(RedirectToAction(nameof(Index))); } ViewBag.CategoryId = new SelectList(categories, $"{nameof(Category.Id)}", $"{nameof(Category.Description)}", recurringPaymentVM.CategoryId); ViewBag.IntervalId = new SelectList(intervals, $"{nameof(Interval.Id)}", $"{nameof(Interval.Description)}", recurringPaymentVM.IntervalId); ViewBag.PaymentTypeId = new SelectList(paymentTypes, $"{nameof(PaymentType.Id)}", $"{nameof(PaymentType.Description)}", recurringPaymentVM.PaymentTypeId); return(View(recurringPaymentVM)); }
public void CheckIfRepeatable_ValidatedRecurrence(PaymentRecurrence recurrence, int amountOfDaysPassed) { var account = new AccountViewModel { Id = 2 }; var recurringPayment = new RecurringPaymentViewModel { Id = 4, Recurrence = recurrence, StartDate = new DateTime(2015, 08, 25), ChargedAccountId = 2, ChargedAccount = account, Amount = 105 }; RecurringPaymentHelper.CheckIfRepeatable(recurringPayment, new PaymentViewModel { Date = DateTime.Today.AddDays(-amountOfDaysPassed), IsCleared = true }) .ShouldBeTrue(); }
public void CheckIfRepeatable_ValidatedRecurrenceMonthly_False() { var account = new AccountViewModel { Id = 2 }; var recurringPayment = new RecurringPaymentViewModel { Id = 4, Recurrence = PaymentRecurrence.Monthly, StartDate = new DateTime(2015, 08, 25), ChargedAccountId = 2, ChargedAccount = account, Amount = 105 }; RecurringPaymentHelper.CheckIfRepeatable(recurringPayment, new PaymentViewModel { Date = DateTime.Today.GetFirstDayOfMonth(), IsCleared = true }) .ShouldBeFalse(); }
public void GetPaymentFromRecurring_CorrectMappedPayment(PaymentRecurrence recurrence) { var account = new AccountViewModel { Id = 2 }; var recurringPayment = new RecurringPaymentViewModel { Id = 4, Recurrence = recurrence, StartDate = new DateTime(2015, 08, DateTime.Today.Day), ChargedAccountId = 2, ChargedAccount = account, Amount = 105 }; var result = RecurringPaymentHelper.GetPaymentFromRecurring(recurringPayment); result.ChargedAccount.ShouldBe(account); result.ChargedAccountId.ShouldBe(account.Id); result.Amount.ShouldBe(105); result.Date.ShouldBe(DateTime.Today); }
public void SavePayment_RecPayment_RecPaymentSaved() { var recPaymentToSave = new RecurringPaymentViewModel { Id = 3, Amount = 300 }; var payment = new PaymentViewModel { Id = 2, RecurringPaymentId = 3, RecurringPayment = recPaymentToSave, IsRecurring = true }; var recPaymentSaved = new RecurringPaymentViewModel(); var paymentRepositorySetup = new Mock <IPaymentRepository>(); paymentRepositorySetup.Setup(x => x.GetList(null)) .Returns(new List <PaymentViewModel> { payment }); var recPaymentRepositorySetup = new Mock <IRecurringPaymentRepository>(); recPaymentRepositorySetup.Setup(x => x.Save(It.IsAny <RecurringPaymentViewModel>())) .Callback((RecurringPaymentViewModel recPay) => recPaymentSaved = recPay); new PaymentManager(paymentRepositorySetup.Object, new Mock <IAccountRepository>().Object, recPaymentRepositorySetup.Object, new Mock <IDialogService>().Object).SavePayment(payment); payment.IsRecurring.ShouldBeTrue(); payment.RecurringPayment.ShouldBe(recPaymentSaved); }
/// <summary> /// Creates an PaymentViewModel based on the recurring PaymentViewModel. /// </summary> /// <param name="recurringPayment">The recurring PaymentViewModel the new PaymentViewModel shall be based on.</param> /// <returns>The new created PaymentViewModel</returns> public static PaymentViewModel GetPaymentFromRecurring(RecurringPaymentViewModel recurringPayment) { var date = DateTime.Today; //If the PaymentViewModel is monthly we want it on the same day of month again. if (recurringPayment.Recurrence == PaymentRecurrence.Monthly) { date = DateTime.Today.AddDays(recurringPayment.StartDate.Day - DateTime.Today.Day); double value = recurringPayment.StartDate.Day; //the Day value i.e. 31 double max = DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month); double difference = -(value - max); if (difference < 0) { date = date.AddDays(difference); } } return(new PaymentViewModel { ChargedAccount = recurringPayment.ChargedAccount, ChargedAccountId = recurringPayment.ChargedAccountId, TargetAccount = recurringPayment.TargetAccount, TargetAccountId = recurringPayment.TargetAccountId, Date = date, IsRecurring = true, Amount = recurringPayment.Amount, Category = recurringPayment.Category, CategoryId = recurringPayment.CategoryId, Type = recurringPayment.Type, RecurringPaymentId = recurringPayment.Id, RecurringPayment = recurringPayment, Note = recurringPayment.Note }); }
public void GetPaymentFromRecurring_MonthlyPayment_CorrectMappedPayment() { var account = new AccountViewModel { Id = 2 }; var dayOfMonth = 26; var recurringPayment = new RecurringPaymentViewModel { Id = 4, Recurrence = PaymentRecurrence.Monthly, StartDate = new DateTime(2015, 08, dayOfMonth), ChargedAccountId = 2, ChargedAccount = account, Amount = 105 }; var result = RecurringPaymentHelper.GetPaymentFromRecurring(recurringPayment); result.ChargedAccount.ShouldBe(account); result.ChargedAccountId.ShouldBe(account.Id); result.Amount.ShouldBe(105); result.Date.ShouldBe(new DateTime(DateTime.Today.Year, DateTime.Today.Month, dayOfMonth)); }
public void GetPaymentFromRecurring_CorrectMappedPayment(PaymentRecurrence recurrence) { var account = new AccountViewModel {Id = 2}; var recurringPayment = new RecurringPaymentViewModel { Id = 4, Recurrence = recurrence, StartDate = new DateTime(2015, 08, DateTime.Today.Day), ChargedAccountId = 2, ChargedAccount = account, Amount = 105 }; var result = RecurringPaymentHelper.GetPaymentFromRecurring(recurringPayment); result.ChargedAccount.ShouldBe(account); result.ChargedAccountId.ShouldBe(account.Id); result.Amount.ShouldBe(105); result.Date.ShouldBe(DateTime.Today); }
public void CheckIfRepeatable_ValidatedRecurrence(PaymentRecurrence recurrence, int amountOfDaysPassed) { var account = new AccountViewModel {Id = 2}; var recurringPayment = new RecurringPaymentViewModel { Id = 4, Recurrence = recurrence, StartDate = new DateTime(2015, 08, 25), ChargedAccountId = 2, ChargedAccount = account, Amount = 105 }; RecurringPaymentHelper.CheckIfRepeatable(recurringPayment, new PaymentViewModel {Date = DateTime.Today.AddDays(-amountOfDaysPassed), IsCleared = true}) .ShouldBeTrue(); }
public void SavePayment_RecPayment_RecPaymentSaved() { var recPaymentToSave = new RecurringPaymentViewModel {Id = 3, Amount = 300}; var payment = new PaymentViewModel { Id = 2, RecurringPaymentId = 3, RecurringPayment = recPaymentToSave, IsRecurring = true }; var recPaymentSaved = new RecurringPaymentViewModel(); var paymentRepositorySetup = new Mock<IPaymentRepository>(); paymentRepositorySetup.Setup(x => x.GetList(null)) .Returns(new List<PaymentViewModel> {payment}); var recPaymentRepositorySetup = new Mock<IRecurringPaymentRepository>(); recPaymentRepositorySetup.Setup(x => x.Save(It.IsAny<RecurringPaymentViewModel>())) .Callback((RecurringPaymentViewModel recPay) => recPaymentSaved = recPay); new PaymentManager(paymentRepositorySetup.Object, new Mock<IAccountRepository>().Object, recPaymentRepositorySetup.Object, new Mock<IDialogService>().Object).SavePayment(payment); payment.IsRecurring.ShouldBeTrue(); payment.RecurringPayment.ShouldBe(recPaymentSaved); }
private RecurringPaymentViewModel ModelToVm(RecurringPayment recurringPayment, RecurringPaymentViewModel recurringPaymentVM, List <Interval> intervals) { dataLayer.Load(recurringPayment, rp => rp.Category); dataLayer.Load(recurringPayment, rp => rp.Interval); dataLayer.Load(recurringPayment, rp => rp.PaymentType); //recurringPaymentVM.ApplicationUser = ApplicationUser; recurringPaymentVM.Id = recurringPayment.Id; recurringPaymentVM.CategoryId = recurringPayment.CategoryId; recurringPaymentVM.CategoryDescription = recurringPayment.Category.Description; recurringPaymentVM.Cost = recurringPayment.Cost; recurringPaymentVM.Description = recurringPayment.Description; recurringPaymentVM.Earnings = recurringPayment.Earnings; recurringPaymentVM.EndDate = recurringPayment.EndDate; recurringPaymentVM.IntervalId = recurringPayment.IntervalId; recurringPaymentVM.IntervalDescription = recurringPayment.Interval.Description; recurringPaymentVM.IsActive = recurringPayment.IsActive; recurringPaymentVM.PaymentTypeId = recurringPayment.PaymentTypeId; recurringPaymentVM.PaymentTypeDescription = recurringPayment.PaymentType.Description; recurringPaymentVM.LastUpdate = recurringPayment.LastUpdate; recurringPaymentVM.NextDate = intervals.Single(i => i.Id == recurringPayment.IntervalId).NextDateTime(recurringPayment.LastUpdate); recurringPaymentVM.Tag = recurringPayment.Tag; recurringPaymentVM.Warranty = recurringPayment.Warranty; recurringPaymentVM.DateCreated = recurringPayment.DateCreated; return(recurringPaymentVM); }
public void CheckIfRepeatable_UnclearedPayment_ReturnFalse(PaymentRecurrence recurrence, int amountOfDaysUntilRepeat) { var account = new AccountViewModel {Id = 2}; var recurringPayment = new RecurringPaymentViewModel { Id = 4, Recurrence = PaymentRecurrence.Weekly, StartDate = new DateTime(2015, 08, 25), ChargedAccountId = 2, ChargedAccount = account, Amount = 105 }; RecurringPaymentHelper.CheckIfRepeatable(recurringPayment, new PaymentViewModel {Date = DateTime.Today.AddDays(amountOfDaysUntilRepeat)}).ShouldBeFalse(); }