Ejemplo n.º 1
0
        public ActionResult Setting_Upload(string key, HttpPostedFileBase file)
        {
            string relativePath  = "/Upload/setting/";
            string AabsolutePath = Server.MapPath(relativePath);
            string filename      = String.Format(key + "-{0}-{1}-{2}-{3}-{4}-{5}-{6}",
                                                 DateTime.Now.Year,
                                                 DateTime.Now.Month.ToString("D2"),
                                                 DateTime.Now.Day.ToString("D2"),
                                                 DateTime.Now.Hour.ToString("D2"),
                                                 DateTime.Now.Minute.ToString("D2"),
                                                 DateTime.Now.Second.ToString("D2"),
                                                 Guid.NewGuid().ToString("N") + Path.GetExtension(file.FileName));
            string imgUrl = relativePath + filename;

            if (!Directory.Exists(Path.GetDirectoryName(AabsolutePath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(AabsolutePath));
            }
            file.SaveAs(AabsolutePath + filename);
            var query = entity.lay_setting.FirstOrDefault(p => p.key == key);

            if (query == null)
            {
                query = new lay_setting()
                {
                    key = key, value = null
                };
                entity.lay_setting.Add(query);
            }
            query.value = imgUrl;
            return(Json(entity.SaveChanges() > 0, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult Setting_Save(string key, string value)
        {
            var query = entity.lay_setting.FirstOrDefault(p => p.key == key);

            if (query == null)
            {
                query = new lay_setting()
                {
                    key = key, value = null
                };
                entity.lay_setting.Add(query);
            }
            query.value = value;
            return(Json(entity.SaveChanges() > 0, JsonRequestBehavior.AllowGet));
        }