예제 #1
0
        public ActionResult Customers()
        {
            SiteCustomersViewModel viewModel = new SiteCustomersViewModel();

            viewModel.Customers = this.doctrineShipsServices.GetCustomers();

            // Set the ViewBag to the TempData status value passed from the Add & Delete methods.
            ViewBag.Status = TempData["Status"];

            return View(viewModel);
        }
예제 #2
0
        public ActionResult DeleteCustomer(SiteCustomersViewModel viewModel)
        {
            if (viewModel.RemoveList != null)
            {
                // Create a collection for the results of the delete operations.
                ICollection<bool> resultList = new List<bool>();

                foreach (var customerId in viewModel.RemoveList)
                {
                    resultList.Add(this.doctrineShipsServices.DeleteCustomer(customerId));
                }

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

            return RedirectToAction("Customers");
        }
예제 #3
0
        public ActionResult AddCustomer(SiteCustomersViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                IValidationResult validationResult = this.doctrineShipsServices.AddCustomer(viewModel.Name, viewModel.Type);

                // If the validationResult is not valid, something did not validate in the service layer.
                if (validationResult.IsValid)
                {
                    TempData["Status"] = "The customer was successfully added.";
                }
                else
                {
                    TempData["Status"] = "Error: The customer 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("Customers");
            }
            else
            {
                // Re-populate the view model and return with any validation errors.
                viewModel.Customers = this.doctrineShipsServices.GetCustomers();
                return View("~/Views/Site/Customers.cshtml", viewModel);
            }
        }