private void MapCampaignDonor(DonationAdminModel model, CampaignDonor campaignDonor)
        {
            campaignDonor.Amount = model.Amount;
            campaignDonor.FirstName = model.FirstName;
            campaignDonor.LastName = model.LastName;
            campaignDonor.Email = model.Email;
            campaignDonor.PrimaryPhone = model.PrimaryPhone;
            campaignDonor.AddressLine1 = model.AddressLine1;
            campaignDonor.AddressLine2 = model.AddressLine2;
            campaignDonor.City = model.City;
            campaignDonor.State = model.State;
            campaignDonor.ZipCode = model.ZipCode;
            campaignDonor.IsAnonymous = model.IsAnonymous;
            campaignDonor.Approved = model.IsApproved;

            if (campaignDonor.CampaignID != model.CampaignID)
            {
                var oldCampaign = campaignDonor.Campaign;
                var newCampaign = campaignRepository.GetCampaignByID(model.CampaignID);

                if (newCampaign == null)
                {
                    return;
                }

                oldCampaign.CampaignDonors.Remove(campaignDonor);
                newCampaign.CampaignDonors.Add(campaignDonor);
            }
        }
        public ActionResult AdminUpdate(DonationAdminModel model, string context = "list")
        {
            if (!ModelState.IsValid)
            {
                TempData["ModelErrors"] = FindModelErrors();
                TempData["DonationAdminModel"] = model;
                return RedirectToAction("Admin");
            }

            using (new UnitOfWorkScope())
            {
                var donation = campaignDonorRepository.GetDonationByID(model.CampaignDonorID);

                if (donation == null)
                {
                    return HttpNotFound("The donation you are looking for could not be found.");
                }

                MapCampaignDonor(model, donation);
                campaignDonorRepository.Save();
                TempData["UserFeedback"] = string.Format("{0} {1}'s donation of {2} has been saved.",
                    donation.FirstName, donation.LastName, donation.Amount);
            }

            if (context.ToLower() == "campaign")
            {
                return RedirectToAction("Admin", "Campaign");
            }

            return RedirectToAction("List");
        }
        public ActionResult Create(DonationAdminModel model)
        {
            if (!ModelState.IsValid)
            {
                TempData["ModelErrors"] = FindModelErrors();
                TempData["DonationAdminModel"] = model;
                return RedirectToAction("New");
            }

            CampaignDonor campaignDonor;

            using (new UnitOfWorkScope())
            {
                campaignDonor = new CampaignDonor
                                    {
                                        Amount = model.Amount,
                                        FirstName = model.FirstName,
                                        LastName = model.LastName,
                                        AddressLine1 = model.AddressLine1,
                                        AddressLine2 = model.AddressLine2,
                                        City = model.City,
                                        State = model.State,
                                        ZipCode = model.ZipCode,
                                        Email = model.Email,
                                        PrimaryPhone = model.PrimaryPhone,
                                        Approved = model.IsApproved,
                                        IsAnonymous = model.IsAnonymous
                                    };

                var campaign = campaignRepository.GetCampaignByID(model.CampaignID);
                campaign.CampaignDonors.Add(campaignDonor);
                var userProfile = userProfileRepository.FindUserProfileByEmail(model.Email).FirstOrDefault();

                if (userProfile != null)
                {
                    userProfile.CampaignDonors.Add(campaignDonor);
                }

                campaignDonorRepository.Save();
            }

            TempData["UserFeedback"] = string.Format("{0} {1}'s donation of {2} has been created successfully.",
                campaignDonor.FirstName, campaignDonor.LastName, campaignDonor.Amount);
            return RedirectToAction("Admin", new { id = campaignDonor.CampaignDonorID });
        }
        public void AdminUpdate_Should_Update_CampaignDonor_Properties_When_Successful()
        {
            var mocks = new MockRepository();
            SetUpController(mocks);
            var donation = EntityHelpers.GetValidCampaignDonor();
            var campaign = EntityHelpers.GetValidCampaign();
            campaignRepository.Add(campaign);
            donation.CampaignID = campaign.CampaignID;
            donation.Campaign = campaign;
            campaignDonorRepository.Add(donation);
            var id = donation.CampaignDonorID;
            var model = new DonationAdminModel
                            {
                                CampaignDonorID = id,
                                Amount = 1234.56m,
                                Email = "some-other-email",
                                FirstName = "some",
                                LastName = "guy",
                                AddressLine1 = "asdf",
                                AddressLine2 = "yald",
                                City = "townplace",
                                State = "al",
                                ZipCode = "92827",
                                PrimaryPhone = "23434234234",
                                IsApproved = false,
                                IsAnonymous = true
                            };

            controller.AdminUpdate(model);
            donation = campaignDonorRepository.GetDonationByID(id);
            Assert.AreEqual(model.CampaignDonorID, donation.CampaignDonorID);
            Assert.AreEqual(model.Amount, donation.Amount);
            Assert.AreEqual(model.Email, donation.Email);
            Assert.AreEqual(model.FirstName, donation.FirstName);
            Assert.AreEqual(model.LastName, donation.LastName);
            Assert.AreEqual(model.AddressLine1, donation.AddressLine1);
            Assert.AreEqual(model.AddressLine2, donation.AddressLine2);
            Assert.AreEqual(model.City, donation.City);
            Assert.AreEqual(model.State, donation.State);
            Assert.AreEqual(model.ZipCode, donation.ZipCode);
            Assert.AreEqual(model.PrimaryPhone, donation.PrimaryPhone);
            Assert.AreEqual(model.IsApproved, donation.Approved);
            Assert.AreEqual(model.IsAnonymous, donation.IsAnonymous);
        }