コード例 #1
0
        public ActionResult Update( CauseTemplateDetailsModel model )
        {
            using (causeTemplateRepository)
            {
                var causeTemplate = causeTemplateRepository.GetCauseTemplateByID(model.CauseTemplateID);

                if (causeTemplate == null)
                {
                    return HttpNotFound("The project template could not be found.");
                }

                if (!ModelState.IsValid)
                {
                    TempData["CauseTemplateDetailsModel"] = model;
                    return RedirectToAction("Edit", new { id = model.CauseTemplateID });
                }

                MapCauseTemplate(causeTemplate, model);

                // Now save any new images and associate the new image names (URL) with the causeTemplate.
                var results = SaveFiles(causeTemplate);
                var fileErrors = results.Where(r => r.IsError).ToList();
                if (fileErrors.Count() > 0)
                {
                    TempData["CauseTemplateErrors"] = fileErrors;
                    TempData["CauseTemplateDetailsModel"] = model;
                    return RedirectToAction("Edit", new { id = model.CauseTemplateID });
                }

                causeTemplateRepository.Save();
            }

            TempData["UserFeedback"] = "Your changes have been saved. Please allow a few minutes for them to take effect.";
            return RedirectToAction( "List" );
        }
コード例 #2
0
 private static void MapCauseTemplate( CauseTemplate causeTemplate, CauseTemplateDetailsModel model )
 {
     causeTemplate.Name = model.Name;
     causeTemplate.ActionVerb = model.ActionVerb;
     causeTemplate.Active = model.Active;
     causeTemplate.CallToAction = model.CallToAction;
     causeTemplate.AmountIsConfigurable = model.AmountIsConfigurable;
     causeTemplate.DefaultAmount = model.DefaultAmount;
     causeTemplate.DefaultTimespanInDays = model.DefaultTimespanInDays;
     causeTemplate.CutOffDate = model.CutOffDate;
     causeTemplate.DescriptionHtml = model.DescriptionHtml;
     causeTemplate.GoalName = model.GoalName;
     causeTemplate.ImagePath = model.ImagePath;
     causeTemplate.BeforeImagePath = model.BeforeImagePath;
     causeTemplate.AfterImagePath = model.AfterImagePath;
     causeTemplate.Summary = model.Summary;
     causeTemplate.TimespanIsConfigurable = model.TimespanIsConfigurable;
     causeTemplate.VideoEmbedHtml = model.VideoEmbedHtml;
     causeTemplate.InstructionsOpenHtml = model.InstructionsOpenHtml;
     causeTemplate.InstructionsClosedHtml = model.InstructionsClosedHtml;
     causeTemplate.StatisticsHtml = model.StatisticsHtml;
 }
コード例 #3
0
        public ActionResult New( CauseTemplateDetailsModel model )
        {
            if ( !ModelState.IsValid )
            {
                TempData["CauseTemplateDetailsModel"] = model;
                TempData["ModelErrors"] = FindModelErrors();
                return RedirectToAction( "Create" );
            }

            using (OrganizationRepository)
            {
                var organization = OrganizationRepository.GetDefaultOrganization(readOnly: false);
                var causeTemplate = Mapper.Map<CauseTemplateDetailsModel, CauseTemplate>(model);
                organization.CauseTemplates.Add(causeTemplate);
                OrganizationRepository.Save();
            }

            return RedirectToAction( "List" );
        }