Пример #1
0
        private static void MapCampaign(Campaign campaign, CampaignDetailsModel viewModel)
        {
            campaign.Title = viewModel.Title;
            campaign.Description = viewModel.Description;
            var template = campaign.CauseTemplate;

            if (template.AmountIsConfigurable)
            {
                campaign.GoalAmount = viewModel.GoalAmount;
            }

            if (template.TimespanIsConfigurable)
            {
                campaign.EndDate = viewModel.EndDate;
            }
        }
Пример #2
0
        public ActionResult Update(CampaignDetailsModel model, int id = -1)
        {
            using (campaignRepository)
            {
                var campaign = campaignRepository.GetCampaignByID(id);

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

                var userProfile = campaign.UserProfile;

                if (User.Identity.Name.ToLower() != userProfile.Email.ToLower())
                {
                    TempData["ErrorMessage"] = "Sorry, you don't have permission to edit this Campaign.";
                    return RedirectToAction("Index", new { slug = campaign.UrlSlug });
                }

                if (ModelState.IsValid)
                {
                    MapCampaign(campaign, model);
                    campaignRepository.Save();
                    return RedirectToAction("Index", new { slug = campaign.UrlSlug });
                }

                TempData["CampaignDetailsModel"] = model;
                return RedirectToAction("Edit", new { slug = campaign.UrlSlug });
            }
        }