Esempio n. 1
0
 public override void ProcessRequest(HttpContext context)
 {
     if (Method == HttpMethod.HttpPost && IsOnline)
     {
         /// mode
         ///     new 默认 新增
         ///     edit 全集编辑
         ///     quick   快速编辑
         ///     delete  删除
         ///
         //开始获取
         List<string> errors = new List<string>();
         bool isOk = false;
         var req = context.Request;
         var mode = req.Form["Mode"].ToLower().Trim();
         int cid = 0;
         //新增
         if (mode == "new")
         {
             if (req.Form["Title"] == null) errors.Add("title_null");
             if (!string.IsNullOrEmpty(req.Form["Name"]) && !Regex.IsMatch(req.Form["Name"], Validater.OtherName)) errors.Add("name_format");
             CategoriesModel cat = new CategoriesModel();
             cat.Title = string.IsNullOrEmpty(req.Form["Title"]) ? cat.Title : req.Form["Title"].Trim();
             cat.Name = string.IsNullOrEmpty(req.Form["Name"]) ? string.Empty : req.Form["Name"].Trim();
             cat.ThemeGuid = string.IsNullOrEmpty(req.Form["Template"]) ? string.Empty : req.Form["Template"].Trim();
             cat.Des = string.IsNullOrEmpty(req.Form["Des"]) ? "" : req.Form["Des"].Trim();
             if (!string.IsNullOrEmpty(req.Form["Parent"]) && int.TryParse(req.Form["Parent"].Trim(), out cid)) cat.ParentID = cid;
             else cat.ParentID = 0;
             isOk = Service.CategoriesService.Add(cat, errors);
         }
         //修改
         else if (mode == "edit")
         {
             if (string.IsNullOrEmpty(req.Form["CatID"]) || !int.TryParse(req.Form["CatID"], out cid) || cid <= 0) errors.Add("categoryid_null");
             if (!string.IsNullOrEmpty(req.Form["Name"]) && !Regex.IsMatch(req.Form["Name"], Validater.OtherName)) errors.Add("name_format");
             CategoriesModel cat = Service.CategoriesService.One(cid);
             if (cat == null) errors.Add("category_null");
             else
             {
                 cat.ID = cid;
                 cat.Title = string.IsNullOrEmpty(req.Form["Title"]) ? cat.Title : req.Form["Title"].Trim();
                 cat.Name = string.IsNullOrEmpty(req.Form["Name"]) ? string.Empty : req.Form["Name"].Trim();
                 cat.ThemeGuid = string.IsNullOrEmpty(req.Form["Template"]) ? cat.ThemeGuid : req.Form["Template"].Trim();
                 cat.Des = string.IsNullOrEmpty(req.Form["Des"]) ? "" : req.Form["Des"].Trim();
                 if (!string.IsNullOrEmpty(req.Form["Parent"]) && int.TryParse(req.Form["Parent"].Trim(), out cid)) cat.ParentID = cid;
                 else cat.ParentID = 0;
                 isOk = Service.CategoriesService.Update(cat, errors);
             }
         }
         //快速编辑
         else if (mode == "quick")
         {
             if (string.IsNullOrEmpty(req.Form["CatID"]) || !int.TryParse(req.Form["CatID"], out cid) || cid <= 0) errors.Add("categoryid_null");
             if (!string.IsNullOrEmpty(req.Form["Name"]) && !Regex.IsMatch(req.Form["Name"], Validater.OtherName)) errors.Add("name_format");
             CategoriesModel cat = Service.CategoriesService.One(cid);
             if (cat == null) errors.Add("category_null");
             else
             {
                 cat.ID = cid;
                 cat.Title = string.IsNullOrEmpty(req.Form["Title"]) ? cat.Title : req.Form["Title"].Trim();
                 cat.Name = string.IsNullOrEmpty(req.Form["Name"]) ? string.Empty : req.Form["Name"].Trim();
                 isOk = Service.CategoriesService.Update(cat, errors);
             }
         }
         //删除
         else if (mode == "delete")
         {
             if (string.IsNullOrEmpty(req.Form["CatID"]) || !int.TryParse(req.Form["CatID"], out cid) || cid <= 0) errors.Add("categoryid_null");
             else
             {
                 isOk = Service.CategoriesService.Delete(cid, false);
                 if (!isOk) errors.Add("on_delete_error");
             }
         }
         context.Response.Write(JsonConvert.SerializeObject(isOk ? (object)new { result = "ok" } : new { result = "no", errors = errors }));
         return;
     }
     base.ProcessRequest(context);
 }
Esempio n. 2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Cats = Service.CategoriesService.GetList(true);
     string mode = string.IsNullOrEmpty(Request.QueryString["mode"]) ? "new" : Request.QueryString["mode"].ToLower().Trim();
     if (mode == "edit")
     {
         int cid = 0;
         if (int.TryParse(Request.QueryString["cid"].Trim(), out cid))
         {
             //获取
             updateCat = Service.CategoriesService.One(cid);
             if (updateCat != null) isEdit = true;//修改
         }
     }
 }