public ActionResult ProcessNextPayment(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) { return(AccessDeniedView()); } var payment = _orderService.GetRecurringPaymentById(id); if (payment == null) { //No recurring payment found with the specified id return(RedirectToAction("List")); } ViewData["selectedTab"] = "history"; try { _orderProcessingService.ProcessNextRecurringPayment(payment); var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.NextPaymentProcessed"), false); return(View(model)); } catch (Exception exc) { //error var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); ErrorNotification(exc, false); return(View(model)); } }
public async Task <IActionResult> Edit(RecurringPaymentModel model, bool continueEditing) { var payment = await _orderService.GetRecurringPaymentById(model.Id); if (payment == null || payment.Deleted) { //No recurring payment found with the specified id return(RedirectToAction("List")); } payment.CycleLength = model.CycleLength; payment.CyclePeriodId = model.CyclePeriodId; payment.TotalCycles = model.TotalCycles; payment.IsActive = model.IsActive; await _orderService.UpdateRecurringPayment(payment); SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.Updated")); if (continueEditing) { //selected tab SaveSelectedTabIndex(); return(RedirectToAction("Edit", new { id = payment.Id })); } return(RedirectToAction("List")); }
private void PrepareRecurringPaymentModel(RecurringPaymentModel model, RecurringPayment recurringPayment, bool includeHistory) { Guard.NotNull(model, nameof(model)); Guard.NotNull(recurringPayment, nameof(recurringPayment)); model.Id = recurringPayment.Id; model.CycleLength = recurringPayment.CycleLength; model.CyclePeriodId = recurringPayment.CyclePeriodId; model.CyclePeriodStr = recurringPayment.CyclePeriod.GetLocalizedEnum(_localizationService, _workContext); model.TotalCycles = recurringPayment.TotalCycles; model.StartDate = _dateTimeHelper.ConvertToUserTime(recurringPayment.StartDateUtc, DateTimeKind.Utc).ToString(); model.IsActive = recurringPayment.IsActive; model.NextPaymentDate = recurringPayment.NextPaymentDate.HasValue ? _dateTimeHelper.ConvertToUserTime(recurringPayment.NextPaymentDate.Value, DateTimeKind.Utc).ToString() : ""; model.CyclesRemaining = recurringPayment.CyclesRemaining; model.InitialOrderId = recurringPayment.InitialOrder.Id; var customer = recurringPayment.InitialOrder.Customer; model.CustomerId = customer.Id; model.CustomerEmail = customer.IsGuest() ? T("Admin.Customers.Guest").Text : customer.Email; model.PaymentType = _paymentService.GetRecurringPaymentType(recurringPayment.InitialOrder.PaymentMethodSystemName).GetLocalizedEnum(_localizationService, _workContext); model.CanCancelRecurringPayment = _orderProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment); if (includeHistory) { foreach (var rph in recurringPayment.RecurringPaymentHistory.OrderBy(x => x.CreatedOnUtc)) { var rphModel = new RecurringPaymentModel.RecurringPaymentHistoryModel(); PrepareRecurringPaymentHistoryModel(rphModel, rph); model.History.Add(rphModel); } } }
public ActionResult ProcessNextPayment(int id) { var payment = _orderService.GetRecurringPaymentById(id); if (payment == null) { return(RedirectToAction("List")); } try { _orderProcessingService.ProcessNextRecurringPayment(payment); var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); NotifySuccess(T("Admin.RecurringPayments.NextPaymentProcessed"), false); return(View(model)); } catch (Exception ex) { var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); NotifyError(ex, false); return(View(model)); } }
public ActionResult List(GridCommand command) { var gridModel = new GridModel <RecurringPaymentModel>(); if (_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) { var payments = _orderService.SearchRecurringPayments(0, 0, 0, null, true); gridModel.Data = payments.PagedForCommand(command).Select(x => { var m = new RecurringPaymentModel(); PrepareRecurringPaymentModel(m, x, false); return(m); }); gridModel.Total = payments.Count; } else { gridModel.Data = Enumerable.Empty <RecurringPaymentModel>(); NotifyAccessDenied(); } return(new JsonResult { Data = gridModel }); }
/// <summary> /// Prepare recurring payment model /// </summary> /// <param name="model">Recurring payment model</param> /// <param name="recurringPayment">Recurring payment</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Recurring payment model</returns> public virtual RecurringPaymentModel PrepareRecurringPaymentModel(RecurringPaymentModel model, RecurringPayment recurringPayment, bool excludeProperties = false) { if (recurringPayment == null) { return(model); } //fill in model values from the entity if (model == null) { model = recurringPayment.ToModel <RecurringPaymentModel>(); } //convert dates to the user time if (recurringPayment.NextPaymentDate.HasValue) { model.NextPaymentDate = _dateTimeHelper.ConvertToUserTime(recurringPayment.NextPaymentDate.Value, DateTimeKind.Utc).ToString(CultureInfo.InvariantCulture); } model.StartDate = _dateTimeHelper.ConvertToUserTime(recurringPayment.StartDateUtc, DateTimeKind.Utc).ToString(CultureInfo.InvariantCulture); model.CustomerId = recurringPayment.InitialOrder.CustomerId; model.InitialOrderId = recurringPayment.InitialOrder.Id; model.CustomerEmail = recurringPayment.InitialOrder.Customer.IsRegistered() ? recurringPayment.InitialOrder.Customer.Email : _localizationService.GetResource("Admin.Customers.Guest"); model.PaymentType = _localizationService.GetLocalizedEnum(_paymentService .GetRecurringPaymentType(recurringPayment.InitialOrder.PaymentMethodSystemName)); model.CanCancelRecurringPayment = _orderProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment); //prepare nested search model PrepareRecurringPaymentHistorySearchModel(model.RecurringPaymentHistorySearchModel, recurringPayment); return(model); }
public ActionResult Edit(RecurringPaymentModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageRecurringPayments)) { return(AccessDeniedView()); } var payment = _orderService.GetRecurringPaymentById(model.Id); if (payment == null || payment.Deleted) { //No recurring payment found with the specified id return(RedirectToAction("List")); } payment.CycleLength = model.CycleLength; payment.CyclePeriodId = model.CyclePeriodId; payment.TotalCycles = model.TotalCycles; payment.IsActive = model.IsActive; _orderService.UpdateRecurringPayment(payment); SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.Updated")); if (continueEditing) { //selected tab SaveSelectedTabIndex(); return(RedirectToAction("Edit", new { id = payment.Id })); } return(RedirectToAction("List")); }
protected virtual void PrepareRecurringPaymentModel(RecurringPaymentModel model, RecurringPayment recurringPayment) { if (model == null) { throw new ArgumentNullException("model"); } if (recurringPayment == null) { throw new ArgumentNullException("recurringPayment"); } model.Id = recurringPayment.Id; model.CycleLength = recurringPayment.CycleLength; model.CyclePeriodId = recurringPayment.CyclePeriodId; model.CyclePeriodStr = recurringPayment.CyclePeriod.GetLocalizedEnum(_localizationService, _workContext); model.TotalCycles = recurringPayment.TotalCycles; model.StartDate = _dateTimeHelper.ConvertToUserTime(recurringPayment.StartDateUtc, DateTimeKind.Utc).ToString(); model.IsActive = recurringPayment.IsActive; model.NextPaymentDate = recurringPayment.NextPaymentDate.HasValue ? _dateTimeHelper.ConvertToUserTime(recurringPayment.NextPaymentDate.Value, DateTimeKind.Utc).ToString() : ""; model.CyclesRemaining = recurringPayment.CyclesRemaining; model.InitialOrderId = recurringPayment.InitialOrder.Id; var customer = EngineContext.Current.Resolve <ICustomerService>().GetCustomerById(recurringPayment.InitialOrder.CustomerId); model.CustomerId = customer.Id; model.CustomerEmail = customer.IsRegistered() ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest"); model.PaymentType = _paymentService.GetRecurringPaymentType(recurringPayment.InitialOrder.PaymentMethodSystemName).GetLocalizedEnum(_localizationService, _workContext); model.CanCancelRecurringPayment = _orderProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment); }
/// <summary> /// Prepare paged recurring payment list model /// </summary> /// <param name="searchModel">Recurring payment search model</param> /// <returns>Recurring payment list model</returns> public virtual RecurringPaymentListModel PrepareRecurringPaymentListModel(RecurringPaymentSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get recurringPayments var recurringPayments = _orderService.SearchRecurringPayments(showHidden: true, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); //prepare list model var model = new RecurringPaymentListModel { Data = recurringPayments.Select(recurringPayment => { //fill in model values from the entity var recurringPaymentModel = new RecurringPaymentModel { Id = recurringPayment.Id, CycleLength = recurringPayment.CycleLength, CyclePeriodId = recurringPayment.CyclePeriodId, TotalCycles = recurringPayment.TotalCycles, IsActive = recurringPayment.IsActive, CyclesRemaining = recurringPayment.CyclesRemaining, CustomerId = recurringPayment.InitialOrder.CustomerId }; //convert dates to the user time if (recurringPayment.NextPaymentDate.HasValue) { recurringPaymentModel.NextPaymentDate = _dateTimeHelper .ConvertToUserTime(recurringPayment.NextPaymentDate.Value, DateTimeKind.Utc).ToString(CultureInfo.InvariantCulture); } recurringPaymentModel.StartDate = _dateTimeHelper .ConvertToUserTime(recurringPayment.StartDateUtc, DateTimeKind.Utc).ToString(CultureInfo.InvariantCulture); //fill in additional values (not existing in the entity) recurringPaymentModel.CyclePeriodStr = _localizationService.GetLocalizedEnum(recurringPayment.CyclePeriod); recurringPaymentModel.CustomerEmail = recurringPayment.InitialOrder.Customer.IsRegistered() ? recurringPayment.InitialOrder.Customer.Email : _localizationService.GetResource("Admin.Customers.Guest"); return(recurringPaymentModel); }), Total = recurringPayments.TotalCount }; return(model); }
public ActionResult CancelRecurringPayment(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageRecurringPayments)) { return(AccessDeniedView()); } var payment = _orderService.GetRecurringPaymentById(id); if (payment == null) { //No recurring payment found with the specified id return(RedirectToAction("List")); } try { var errors = _orderProcessingService.CancelRecurringPayment(payment); var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment); if (errors.Count > 0) { foreach (var error in errors) { ErrorNotification(error, false); } } else { SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.Cancelled"), false); } //selected tab SaveSelectedTabIndex(persistForTheNextRequest: false); return(View(model)); } catch (Exception exc) { //error var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment); ErrorNotification(exc, false); //selected tab SaveSelectedTabIndex(persistForTheNextRequest: false); return(View(model)); } }
public ActionResult Edit(int id) { var payment = _orderService.GetRecurringPaymentById(id); if (payment == null || payment.Deleted) { return(RedirectToAction("List")); } var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); return(View(model)); }
public virtual ActionResult ProcessNextPayment(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageRecurringPayments)) { return(AccessDeniedView()); } var payment = _subscriptionService.GetRecurringPaymentById(id); if (payment == null) { //No recurring payment found with the specified id return(RedirectToAction("List")); } try { var errors = _subscriptionProcessingService.ProcessNextRecurringPayment(payment); var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment); if (errors.Any()) { errors.ToList().ForEach(error => ErrorNotification(error, false)); } else { SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.NextPaymentProcessed"), false); } //selected tab SaveSelectedTabName(persistForTheNextRequest: false); return(View(model)); } catch (Exception exc) { //error var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment); ErrorNotification(exc, false); //selected tab SaveSelectedTabName(persistForTheNextRequest: false); return(View(model)); } }
//edit public IActionResult Edit(string id) { var payment = _orderService.GetRecurringPaymentById(id); if (payment == null || payment.Deleted) { //No recurring payment found with the specified id return(RedirectToAction("List")); } var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment); return(View(model)); }
public async Task <IActionResult> CancelRecurringPayment(string id) { var payment = await _orderService.GetRecurringPaymentById(id); if (payment == null) { //No recurring payment found with the specified id return(RedirectToAction("List")); } try { var errors = await _orderProcessingService.CancelRecurringPayment(payment); var model = new RecurringPaymentModel(); await PrepareRecurringPaymentModel(model, payment); if (errors.Count > 0) { foreach (var error in errors) { ErrorNotification(error, false); } } else { SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.Cancelled"), false); } //selected tab SaveSelectedTabIndex(persistForTheNextRequest: false); return(View(model)); } catch (Exception exc) { //error var model = new RecurringPaymentModel(); await PrepareRecurringPaymentModel(model, payment); ErrorNotification(exc, false); //selected tab SaveSelectedTabIndex(persistForTheNextRequest: false); return(View(model)); } }
public IActionResult List(DataSourceRequest command) { var payments = _orderService.SearchRecurringPayments("", "", "", null, command.Page - 1, command.PageSize, true); var gridModel = new DataSourceResult { Data = payments.Select(x => { var m = new RecurringPaymentModel(); PrepareRecurringPaymentModel(m, x); return(m); }), Total = payments.TotalCount, }; return(Json(gridModel)); }
//edit public ActionResult Edit(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) { return(AccessDeniedView()); } var payment = _orderService.GetRecurringPaymentById(id); if (payment == null || payment.Deleted) { throw new ArgumentException("No recurring payment found with the specified id", "id"); } var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); return(View(model)); }
public ActionResult Edit(RecurringPaymentModel model, bool continueEditing) { var payment = _orderService.GetRecurringPaymentById(model.Id); if (payment == null || payment.Deleted) { return(RedirectToAction("List")); } payment.CycleLength = model.CycleLength; payment.CyclePeriodId = model.CyclePeriodId; payment.TotalCycles = model.TotalCycles; payment.IsActive = model.IsActive; _orderService.UpdateRecurringPayment(payment); NotifySuccess(T("Admin.RecurringPayments.Updated")); return(continueEditing ? RedirectToAction("Edit", payment.Id) : RedirectToAction("List")); }
public ActionResult CancelRecurringPayment(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) { return(AccessDeniedView()); } var payment = _orderService.GetRecurringPaymentById(id); if (payment == null) { throw new ArgumentException("No recurring payment found with the specified id"); } ViewData["selectedTab"] = "history"; try { var errors = _orderProcessingService.CancelRecurringPayment(payment); var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); if (errors.Count > 0) { foreach (var error in errors) { ErrorNotification(error, false); } } else { SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.Cancelled"), false); } return(View(model)); } catch (Exception exc) { //error var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); ErrorNotification(exc, false); return(View(model)); } }
public ActionResult List(GridCommand command) { var gridModel = new GridModel <RecurringPaymentModel>(); var payments = _orderService.SearchRecurringPayments(0, 0, 0, null, true); gridModel.Data = payments.PagedForCommand(command).Select(x => { var m = new RecurringPaymentModel(); PrepareRecurringPaymentModel(m, x, false); return(m); }); gridModel.Total = payments.Count; return(new JsonResult { Data = gridModel }); }
public virtual IActionResult Edit(RecurringPaymentModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageRecurringPayments)) { return(AccessDeniedView()); } //try to get a recurring payment with the specified id var payment = _orderService.GetRecurringPaymentById(model.Id); if (payment == null || payment.Deleted) { return(RedirectToAction("List")); } if (ModelState.IsValid) { payment.CycleLength = model.CycleLength; payment.CyclePeriodId = model.CyclePeriodId; payment.TotalCycles = model.TotalCycles; payment.IsActive = model.IsActive; _orderService.UpdateRecurringPayment(payment); SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.Updated")); if (!continueEditing) { return(RedirectToAction("List")); } //selected tab SaveSelectedTabName(); return(RedirectToAction("Edit", new { id = payment.Id })); } //prepare model model = _recurringPaymentModelFactory.PrepareRecurringPaymentModel(model, payment, true); //if we got this far, something failed, redisplay form return(View(model)); }
//edit public ActionResult Edit(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageRecurringPayments)) { return(AccessDeniedView()); } var payment = _orderService.GetRecurringPaymentById(id); if (payment == null || payment.Deleted) { //No recurring payment found with the specified id return(RedirectToAction("List")); } var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment); return(View(model)); }
public ActionResult List(DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageRecurringPayments)) { return(AccessDeniedView()); } var payments = _orderService.SearchRecurringPayments(0, 0, 0, null, command.Page - 1, command.PageSize, true); var gridModel = new DataSourceResult { Data = payments.Select(x => { var m = new RecurringPaymentModel(); PrepareRecurringPaymentModel(m, x); return(m); }), Total = payments.TotalCount, }; return(Json(gridModel)); }
public async Task <IActionResult> List(DataSourceRequest command) { var payments = await _orderService.SearchRecurringPayments("", "", "", null, command.Page - 1, command.PageSize, true); var items = new List <RecurringPaymentModel>(); foreach (var x in payments) { var m = new RecurringPaymentModel(); await PrepareRecurringPaymentModel(m, x); items.Add(m); } var gridModel = new DataSourceResult { Data = items, Total = payments.TotalCount, }; return(Json(gridModel)); }
public ActionResult CancelRecurringPayment(int id) { var payment = _orderService.GetRecurringPaymentById(id); if (payment == null) { return(RedirectToAction("List")); } try { var errors = _orderProcessingService.CancelRecurringPayment(payment); var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); if (errors.Count > 0) { foreach (var error in errors) { NotifyError(error, false); } } else { NotifySuccess(T("Admin.RecurringPayments.Cancelled"), false); } return(View(model)); } catch (Exception ex) { var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); NotifyError(ex, false); return(View(model)); } }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> Edit(RecurringPaymentModel model, bool continueEditing) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageRecurringPayments)) { return(AccessDeniedView()); } //try to get a recurring payment with the specified id var payment = await _orderService.GetRecurringPaymentByIdAsync(model.Id); if (payment == null || payment.Deleted) { return(RedirectToAction("List")); } if (ModelState.IsValid) { payment = model.ToEntity(payment); await _orderService.UpdateRecurringPaymentAsync(payment); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.RecurringPayments.Updated")); if (!continueEditing) { return(RedirectToAction("List")); } return(RedirectToAction("Edit", new { id = payment.Id })); } //prepare model model = await _recurringPaymentModelFactory.PrepareRecurringPaymentModelAsync(model, payment, true); //if we got this far, something failed, redisplay form return(View(model)); }
public IActionResult ProcessNextPayment(string id) { var payment = _orderService.GetRecurringPaymentById(id); if (payment == null) { //No recurring payment found with the specified id return(RedirectToAction("List")); } try { _orderProcessingService.ProcessNextRecurringPayment(payment); var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment); SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.NextPaymentProcessed"), false); //selected tab SaveSelectedTabIndex(persistForTheNextRequest: false); return(View(model)); } catch (Exception exc) { //error var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment); ErrorNotification(exc, false); //selected tab SaveSelectedTabIndex(persistForTheNextRequest: false); return(View(model)); } }
public ActionResult List(GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) { return(AccessDeniedView()); } var payments = _orderService.SearchRecurringPayments(0, 0, 0, null, true); var gridModel = new GridModel <RecurringPaymentModel> { Data = payments.PagedForCommand(command).Select(x => { var m = new RecurringPaymentModel(); PrepareRecurringPaymentModel(m, x, false); return(m); }), Total = payments.Count, }; return(new JsonResult { Data = gridModel }); }