JordanRift.Grassroots.Web.Controllers.AdminController.GenerateDefaultCampaign C# (CSharp) Method

GenerateDefaultCampaign() public method

Request to generate the "General Campaign" for the current month if none exists. Leave public so it can be automated.
public GenerateDefaultCampaign ( ) : System.Web.Mvc.ActionResult
return System.Web.Mvc.ActionResult
        public ActionResult GenerateDefaultCampaign()
        {
            var defaultCampaign = campaignRepository.GetDefaultCampaign();

            if (defaultCampaign.StartDate.Month == DateTime.Now.Month)
            {
                return new HttpStatusCodeResult(403);
            }

            using (new UnitOfWorkScope())
            {
                var organization = OrganizationRepository.GetDefaultOrganization(readOnly: false);
                var causeTemplate = organization.CauseTemplates.FirstOrDefault();
                var root = roleRepository.GetRoot();
                var userProfile = root.UserProfiles.FirstOrDefault();

                if (causeTemplate == null || userProfile == null)
                {
                    return HttpNotFound("The default cause template or root user could not be found");
                }

                var today = DateTime.Now;
                var campaign = new Campaign
                                   {
                                       GoalAmount = causeTemplate.DefaultAmount,
                                       Title = string.Format("General Fund {0}/{1}", today.Month, today.Year),
                                       UrlSlug = string.Format("GeneralFund{0}{1}", today.Month, today.Year),
                                       StartDate = new DateTime(today.Year, today.Month, 1),
                                       // Get the first day of the current month
                                       EndDate = today.AddMonths(1).AddDays(-1),
                                       // Get the last day of the current month
                                       ImagePath = string.Empty,
                                       Description = string.Format("General Fund for month of {0}, {1}", today.Month, today.Year),
                                       IsGeneralFund = true
                                   };

                organization.Campaigns.Add(campaign);
                causeTemplate.Campaigns.Add(campaign);
                userProfile.Campaigns.Add(campaign);
                campaignRepository.Save();
            }

            // Success
            return new HttpStatusCodeResult(200);
        }