Exemplo n.º 1
0
        public ActionResult DeleteSubscriptionPlan(SiteSubscriptionPlansViewModel viewModel)
        {
            if (viewModel.RemoveList != null)
            {
                // Create a collection for the results of the delete operations.
                ICollection<bool> resultList = new List<bool>();

                foreach (var subscriptionPlanId in viewModel.RemoveList)
                {
                    resultList.Add(this.doctrineShipsServices.DeleteSubscriptionPlan(subscriptionPlanId));
                }

                // If any of the deletions failed, output an error message.
                if (resultList.Contains(false))
                {
                    TempData["Status"] = "Error: One or more subscription plans were not removed. Are any of the plans still in use by accounts?";
                }
                else
                {
                    TempData["Status"] = "All selected subscription plans were successfully removed.";
                }
            }

            return RedirectToAction("SubscriptionPlans");
        }
Exemplo n.º 2
0
        public ActionResult SubscriptionPlans()
        {
            SiteSubscriptionPlansViewModel viewModel = new SiteSubscriptionPlansViewModel();

            viewModel.SubscriptionPlans = this.doctrineShipsServices.GetSubscriptionPlans();

            // Set the ViewBag to the TempData status value passed from the add and remove methods.
            ViewBag.Status = TempData["Status"];

            return View(viewModel);
        }
Exemplo n.º 3
0
        public ActionResult AddSubscriptionPlan(SiteSubscriptionPlansViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                // Create an Auto Mapper map between the subscription plan entity and the view model. Ignore the id as this will be auto-generated.
                Mapper.CreateMap<SiteSubscriptionPlansViewModel, SubscriptionPlan>().ForMember(x => x.SubscriptionPlanId, opt => opt.Ignore());

                // Populate a subscription plan with automapper and pass it back to the service layer for addition.
                SubscriptionPlan subscriptionPlan = Mapper.Map<SiteSubscriptionPlansViewModel, SubscriptionPlan>(viewModel);
                IValidationResult validationResult = this.doctrineShipsServices.AddSubscriptionPlan(subscriptionPlan);

                // If the validationResult is not valid, something did not validate in the service layer.
                if (validationResult.IsValid)
                {
                    TempData["Status"] = "The subscription plan was successfully added.";
                }
                else
                {
                    TempData["Status"] = "Error: The subscription plan was not added, a validation error occured.<br /><b>Error Details: </b>";

                    foreach (var error in validationResult.Errors)
                    {
                        TempData["Status"] += error.Value + "<br />";
                    }
                }

                return RedirectToAction("SubscriptionPlans");
            }
            else
            {
                // Re-populate the view model and return with any validation errors.
                viewModel.SubscriptionPlans = this.doctrineShipsServices.GetSubscriptionPlans();
                return View("~/Views/Site/SubscriptionPlans.cshtml", viewModel);
            }
        }