public ActionResult UpdateNotificationRecipients(AccountNotificationRecipientsViewModel viewModel)
        {
            if (viewModel != null)
            {
                // Create an Auto Mapper map between the notification recipient entity and the view model.
                Mapper.CreateMap<AccountNotificationRecipientsViewModel, NotificationRecipient>();

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

                // Populate a notification recipient with automapper and pass it back to the service layer for update.
                NotificationRecipient notificationRecipient = Mapper.Map<AccountNotificationRecipientsViewModel, NotificationRecipient>(viewModel);
                IValidationResult validationResult = this.doctrineShipsServices.UpdateNotificationRecipient(notificationRecipient);

                // If the validationResult is not valid, something did not validate in the service layer.
                if (validationResult.IsValid)
                {
                    TempData["Status"] = "The notification recipient was successfully updated.";
                }
                else
                {
                    TempData["Status"] = "Error: The notification recipient 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("NotificationRecipients");
        }
        public ActionResult DeleteNotificationRecipient(AccountNotificationRecipientsViewModel 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 notificationRecipientId in viewModel.RemoveList)
                {
                    resultList.Add(this.doctrineShipsServices.DeleteNotificationRecipient(accountId, notificationRecipientId));
                }

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

            return RedirectToAction("NotificationRecipients");
        }
        public ActionResult NotificationRecipients()
        {
            AccountNotificationRecipientsViewModel viewModel = new AccountNotificationRecipientsViewModel();

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

            viewModel.NotificationRecipients = this.doctrineShipsServices.GetNotificationRecipients(accountId);

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

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

            if (ModelState.IsValid)
            {
                // Clean the passed parameters.
                string cleanTwitterHandle = Server.HtmlEncode(viewModel.TwitterHandle);
                string cleanDescription = Conversion.StringToSafeString(Server.HtmlEncode(viewModel.Description));

                IValidationResult validationResult = this.doctrineShipsServices.AddNotificationRecipient(accountId, cleanTwitterHandle, cleanDescription);

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