Exemplo n.º 1
0
    private void Save()
    {
        AjaxResult result = new AjaxResult();

        result.IsSuccess = false;
        result.Msg       = "保存失败!";
        int?id = null;

        if (!string.IsNullOrEmpty(Request.Form["id"]))
        {
            id = Convert.ToInt32(Request.Form["id"]);
        }
        News model = null;

        if (!id.HasValue)//新增
        {
            model = new News();
            //   model.GetEntitySearchPars<News>(this.Context);
            model.Author     = "";
            model.IsDelete   = false;
            model.IsTop      = byte.Parse(Request.Form["IsTop"]);
            model.Sort       = int.Parse(Request.Form["Sort"]);
            model.NewTitle   = Request.Form["NewTitle"];
            model.Author     = Request.Form["Author"];
            model.CreateUser = User.UserName;
            model.CreateTime = DateTime.Now;
            model.NewContent = Server.HtmlDecode(Request.Form["SummaryCode"]);
            if (bll.Add(model))
            {
                result.IsSuccess = true;
                result.Msg       = "增加成功!";
            }
        }
        else//编辑
        {
            model = bll.Get(id.Value);
            if (model != null)
            {
                //model.GetEntitySearchPars<News>(this.Context);
                model.IsTop      = byte.Parse(Request.Form["IsTop"]);
                model.Sort       = int.Parse(Request.Form["Sort"]);
                model.NewTitle   = Request.Form["NewTitle"];
                model.Author     = Request.Form["Author"];
                model.NewContent = Server.HtmlDecode(Request.Form["SummaryCode"]);
                if (bll.Update(model))
                {
                    result.IsSuccess = true;
                    result.Msg       = "更新成功!";
                }
            }
        };
        Response.Clear();
        Response.Write(result.ToJsonString());
        Response.ContentType = "application/json";
        Response.End();
    }
    /// <summary>
    /// 获取指定ID的数据
    /// </summary>
    private void GetData()
    {
        var planid = Request.Form["id"] != null?Convert.ToInt32(Request.Form["id"]) : 0;

        var plan    = bll.Get(planid);
        var strJSON = "";

        if (plan != null)
        {
            strJSON = JsonConvert.SerializeObject(plan);
        }

        Response.Clear();
        Response.Write(strJSON);
        Response.ContentType = "application/json";
        Response.End();
    }