public ActionResult ShipFits()
        {
            AccountShipFitsViewModel viewModel = new AccountShipFitsViewModel();

            // Convert the currently logged-in account id to an integer.
            int accountId = Conversion.StringToInt32(User.Identity.Name);

            viewModel.ShipFits = this.doctrineShipsServices.GetShipFitList(accountId);

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

            return View(viewModel);
        }
        public ActionResult UpdateShipFit(AccountShipFitsViewModel viewModel)
        {
            // Convert the currently logged-in account id to an integer.
            int accountId = Conversion.StringToInt32(User.Identity.Name);

            if (ModelState.IsValid)
            {
                // Create an Auto Mapper map between the ship fit entity and the view model.
                Mapper.CreateMap<AccountShipFitsViewModel, ShipFit>();

                // Sanitise the form values.
                viewModel.AccountId = accountId;
                viewModel.Name = Conversion.StringToSafeString(viewModel.Name);
                viewModel.Role = Conversion.StringToSafeString(viewModel.Role);
                viewModel.Notes = Conversion.StringToSafeString(viewModel.Notes);

                // Populate a ship fit with automapper and pass it back to the service layer for update.
                ShipFit shipFit = Mapper.Map<AccountShipFitsViewModel, ShipFit>(viewModel);
                IValidationResult validationResult = this.doctrineShipsServices.UpdateShipFit(shipFit);

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

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

                return RedirectToAction("ShipFits");
            }
            else
            {
                // Re-populate the view model and return with any validation errors.
                viewModel.ShipFits = this.doctrineShipsServices.GetShipFitList(accountId);
                ViewBag.Status = "Error: The ship fit was not updated, a validation error occured.";
                return View("~/Views/Account/ShipFits.cshtml", viewModel);
            }
        }
        public ActionResult DeleteShipFit(AccountShipFitsViewModel viewModel)
        {
            if (viewModel.RemoveList != null)
            {
                // Convert the currently logged-in account id to an integer.
                int accountId = Conversion.StringToInt32(User.Identity.Name);

                // Create a collection for the results of the delete operations.
                ICollection<bool> resultList = new List<bool>();

                foreach (var shipFitId in viewModel.RemoveList)
                {
                    resultList.Add(this.doctrineShipsServices.DeleteShipFit(accountId, shipFitId));
                }

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

            return RedirectToAction("ShipFits");
        }