Inheritance: Entity
        public void CanEnsureSpeakerCreationIsValid()
        {
            Speaker speakerFromForm = new Speaker();
            ViewResult result = controller.Create(speakerFromForm).AssertViewRendered();

            result.ViewData.Model.ShouldNotBeNull();
            result.ViewData.Model.ShouldBeOfType(typeof(SpeakerFormViewModel));
        }
        public void CanCompareSpeakers()
        {
            Speaker instance = new Speaker();
            instance.Name = "Joe Smith";

            instance.Email = "*****@*****.**";

            Speaker instanceToCompareTo = new Speaker();
            instanceToCompareTo.Name = "Joe Smith";
            instanceToCompareTo.Email = "*****@*****.**";

            instance.ShouldEqual(instanceToCompareTo);
        }
        public ActionResult Create(Speaker speaker)
        {
            if (ViewData.ModelState.IsValid)
            {
                ActionConfirmation saveOrUpdateConfirmation = speakerManagementService.SaveOrUpdate(speaker);

                if (saveOrUpdateConfirmation.WasSuccessful)
                {
                    TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = saveOrUpdateConfirmation.Message;
                    return RedirectToAction("Index");
                }
            }

            SpeakerFormViewModel viewModel = speakerManagementService.CreateFormViewModelFor(speaker);
            return View(viewModel);
        }
        /// <summary>
        /// Creates a valid, transient Speaker; typical of something retrieved back from a form submission
        /// </summary>
        private Speaker CreateTransientSpeaker()
        {
            Speaker speaker = new Speaker() {
                Name = "Joe Smith",
                Email = "*****@*****.**",
                Website = "http://wwww.joesmith.com",
                Bio = "Hello World"
            };

            return speaker;
        }
        public ActionConfirmation SaveOrUpdate(Speaker speaker)
        {
            if (speaker.IsValid())
            {
                speakerRepository.SaveOrUpdate(speaker);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The user was successfully saved.");
                saveOrUpdateConfirmation.Value = speaker;

                return saveOrUpdateConfirmation;
            }
            else
            {
                speakerRepository.DbContext.RollbackTransaction();

                return ActionConfirmation.CreateFailureConfirmation(
                    "The user could not be saved due to missing or invalid information.");
            }
        }
 public SpeakerFormViewModel CreateFormViewModelFor(Speaker speaker)
 {
     SpeakerFormViewModel viewModel = CreateFormViewModel();
     viewModel.Speaker = speaker;
     return viewModel;
 }
 private void TransferFormValuesTo(Speaker speakerToUpdate, Speaker speakerFromForm)
 {
     speakerToUpdate.Name = speakerFromForm.Name;
     speakerToUpdate.Email = speakerFromForm.Email;
     speakerToUpdate.Website = speakerFromForm.Website;
     speakerToUpdate.Bio = speakerFromForm.Bio;
 }
        public ActionConfirmation UpdateWith(Speaker speakerFromForm)
        {
            Speaker speakerToUpdate = speakerRepository.Get(speakerFromForm.Id);
            TransferFormValuesTo(speakerToUpdate, speakerFromForm);

            if (speakerToUpdate.IsValid())
            {
                ActionConfirmation updateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The speaker was successfully updated.");
                updateConfirmation.Value = speakerToUpdate;

                return updateConfirmation;
            }
            else
            {
                speakerRepository.DbContext.RollbackTransaction();

                return ActionConfirmation.CreateFailureConfirmation(
                    "The speaker could not be saved due to missing or invalid information.");
            }
        }