コード例 #1
0
        public JsonResult SaveSiteSettings(Settings entity)
        {
            var siteSettings = Context.SiteSettings.FirstOrDefault();

            if (siteSettings == null)
            {
                return(new JsonResult
                {
                    Data = new
                    {
                        success = false,
                        message = "There was an finding the site settings."
                    }
                });
            }


            Mapper.Map(entity, siteSettings);

            var timeZone = Context.Configurations.First(config => config.Key == ConfigSettings.TimeZone.ToString());

            if (timeZone.Value != entity.TimeZoneId)
            {
                timeZone.Value = entity.TimeZoneId;
                SystemTime.TimeZoneChanged();
            }

            var success = Context.SaveChanges();

            if (success > 0)
            {
                // refresh the cache
                SettingsUtils.GetSiteSettings(true);
                return(new JsonResult
                {
                    Data = new
                    {
                        success = true,
                        message = "Settings saved successfully."
                    }
                });
            }

            return(new JsonResult
            {
                Data = new
                {
                    success = false,
                    message = "There was an error processing your request."
                }
            });
        }