Пример #1
0
        //
        // GET: /Api/

        public ActionResult GetSettingOne(string type)
        {
            SettingOneModel m = SettingOneModel.Load();

            m.WelComeImage = FileHelper.MakePath(m.WelComeImage);
            m.News.ForEach(x => x.Image    = FileHelper.MakePath(x.Image));
            m.Leaders.ForEach(x => x.Image = FileHelper.MakePath(x.Image));

            if (string.Equals(type, "json", StringComparison.CurrentCultureIgnoreCase))
            {
                return(Json(m, JsonRequestBehavior.AllowGet));
            }

            XmlSerializer     xml      = new XmlSerializer(m.GetType());
            XmlWriterSettings settings = new XmlWriterSettings();

            //settings.Indent = true;
            settings.NewLineChars = "\r\n";
            settings.Encoding     = Encoding.UTF8;
            MemoryStream stream = new MemoryStream();
            XmlWriter    writer = XmlWriter.Create(stream, settings);

            xml.Serialize(writer, m);
            writer.Close();
            String result = Encoding.UTF8.GetString(stream.ToArray());

            return(Content(result, "application/xml"));
        }
Пример #2
0
        public ActionResult SettingOne(SettingOneModel m)
        {
            var new_images    = this.Request.Files.GetMultiple("new_images");
            var new_names     = this.Request.Form.GetValues("new_names");
            var new_dates     = this.Request.Form.GetValues("new_dates");
            var leader_images = this.Request.Files.GetMultiple("leader_images");
            var leader_names  = this.Request.Form.GetValues("leader_names");
            var leader_dates  = this.Request.Form.GetValues("leader_dates");

            lock (SettingOneLockObject)
            {
                if (m.News == null)
                {
                    m.News = new List <SettingOneModelNew>();
                }
                for (int i = 0; i < new_images.Count; i++)
                {
                    string name     = new_names[i];
                    string filename = new_images[i].Save();
                    m.News.Add(new SettingOneModelNew()
                    {
                        Title = name, Image = filename, Date = new_dates[i]
                    });
                }

                if (m.Leaders == null)
                {
                    m.Leaders = new List <SettingOneModelLeader>();
                }
                for (int i = 0; i < leader_images.Count; i++)
                {
                    string name     = leader_names[i];
                    string filename = leader_images[i].Save();
                    m.Leaders.Add(new SettingOneModelLeader()
                    {
                        Title = name, Image = filename, Date = leader_dates[i]
                    });
                }

                if (string.IsNullOrWhiteSpace(m.WelComeTitle))
                {
                    return(Json(new { success = false, message = "欢迎语不能为空" }));
                }

                HttpPostedFileBase postedfile = this.Request.Files.Get("WelcomeImageFile");
                if (postedfile != null)
                {
                    m.WelComeImage = postedfile.Save();
                }
                if (string.IsNullOrWhiteSpace(m.WelComeImage))
                {
                    return(Json(new { success = false, message = "欢迎图片不能为空" }));
                }
                m.Save();
            }
            return(Json(new { success = true, message = "保存成功" }));
        }
Пример #3
0
        public ActionResult SettingOne()
        {
            SettingOneModel m = SettingOneModel.Load();

            return(View(m));
        }