示例#1
0
        /// <summary>
        /// Gets the cache edit model.
        /// </summary>
        /// <param name="api">The current api</param>
        /// <returns>The model</returns>
        public static ConfigEditModel Get(IApi api)
        {
            var model = new ConfigEditModel();

            using (var config = new Config(api)) {
                model.Cache.PagesExpires = config.CacheExpiresPages;

                model.General.HierarchicalPageSlugs = config.HierarchicalPageSlugs;
                model.General.ExpandedSitemapLevels = config.ManagerExpandedSitemapLevels;
            }
            return(model);
        }
示例#2
0
        /// <summary>
        /// Gets the cache edit model.
        /// </summary>
        /// <param name="api">The current api</param>
        /// <returns>The model</returns>
        public static ConfigEditModel Get(IApi api)
        {
            var model = new ConfigEditModel();

            using (var config = new Config(api))
            {
                model.Cache.PagesExpires = config.CacheExpiresPages;
                model.Cache.PostsExpires = config.CacheExpiresPosts;
                model.Cache.MediaCDN = config.MediaCDN;

                model.General.ArchivePageSize = config.ArchivePageSize;
                model.General.HierarchicalPageSlugs = config.HierarchicalPageSlugs;
                model.General.ExpandedSitemapLevels = config.ManagerExpandedSitemapLevels;
            }
            return model;
        }
示例#3
0
        public ActionResult EditConfig(ConfigEditModel model)
        {
            ViewBag.MenuItem = CurrentMenuItem;

            if (ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(model.ConfigValue2))
                {
                    if (Regex.Matches(model.ConfigValue2, @"[-a-zA-Z0-9, ']").Count < model.ConfigValue2.Length)
                    {
                        ModelState.AddModelError("ConfigValue2", "Value contains invalid characters (Enter A-Z, a-z, 0-9, comma, space, hyphen)");

                        return(View(model));
                    }
                }
                if (!String.IsNullOrEmpty(model.ConfigValue4))
                {
                    if (Regex.Matches(model.ConfigValue4, @"[0-9]").Count < model.ConfigValue4.Length)
                    {
                        ModelState.AddModelError("ConfigValue4", "Value contains invalid characters (Enter 0-9)");

                        return(View(model));
                    }
                }
                if (!String.IsNullOrEmpty(model.ConfigValue5))
                {
                    if (Regex.Matches(model.ConfigValue5, @"[0-9]").Count < model.ConfigValue5.Length)
                    {
                        ModelState.AddModelError("ConfigValue5", "Value contains invalid characters (Enter 0-9)");

                        return(View(model));
                    }
                }

                var config = unitOfWork.Repository <Config>().Queryable().SingleOrDefault(c => c.Id == model.ConfigId);

                if (config == null)
                {
                    ModelState.AddModelError("ConfigType", "Unable to update the configuration. The configuration could not be found in the data store.");

                    return(View(model));
                }

                try
                {
                    string encodedValue = "";
                    switch (config.ConfigType)
                    {
                    case ConfigType.E2BVersion:
                        encodedValue = System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(model.ConfigValue1, false);;
                        break;

                    case ConfigType.WebServiceSubscriberList:
                        encodedValue = System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(model.ConfigValue2, false);;
                        break;

                    case ConfigType.AssessmentScale:
                        encodedValue = System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(model.ConfigValue3, false);;
                        break;

                    case ConfigType.ReportInstanceNewAlertCount:
                        encodedValue = System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(model.ConfigValue4, false);;
                        break;

                    case ConfigType.MedicationOnsetCheckPeriodWeeks:
                        encodedValue = System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(model.ConfigValue5, false);;
                        break;

                    default:
                        break;
                    }
                    config.ConfigValue = encodedValue;

                    unitOfWork.Repository <Config>().Update(config);
                    unitOfWork.Complete();

                    return(Redirect("/Admin/ManageConfig.aspx"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", string.Format("Unable to update the configuration: {0}", ex.Message));
                }
            }

            ViewBag.ConfigValue1Items = new[]
            {
                new SelectListItem {
                    Value = "E2B(R2) ICH Report", Text = "E2B(R2) ICH Report", Selected = true
                },
                new SelectListItem {
                    Value = "E2B(R3) ICH Report", Text = "E2B(R3) ICH Report"
                }
            };

            ViewBag.ConfigValue3Items = new[]
            {
                new SelectListItem {
                    Value = "Both Scales", Text = "Both Scales", Selected = true
                },
                new SelectListItem {
                    Value = "WHO Scale", Text = "WHO Scale"
                },
                new SelectListItem {
                    Value = "Naranjo Scale", Text = "Naranjo Scale"
                }
            };

            return(View(model));
        }