private Model.AjaxResult Action_Commit(HttpContext context, Model.AjaxResult jsonResult) { Model.visitor_message info_model = GetCommitInfo(); string error_msg = CheckCommitInfo(info_model); if (!CheckData.IsStringNull(error_msg)) { return(base.ErrorAjaxResult(jsonResult, error_msg)); } info_model.ipaddress = DTRequest.GetIP(); info_model.TimeAdd = DateTime.Now; BLL.visitor_message bll_vismsg = new BLL.visitor_message(); const int minute_interval = 15; int ip_repeat_count = bll_vismsg.GetIPRepeatCount(info_model.ipaddress, info_model.TimeAdd, 15); if (ip_repeat_count >= 2) { return(base.ErrorAjaxResult(jsonResult, @"您提交的太频繁了, 请" + minute_interval.ToString() + @"分钟后再提交!")); } int rid = bll_vismsg.Add(info_model); if (rid > 0) { jsonResult.Status = Model.AjaxResult.StatusValue.Success; jsonResult.Msg = @"添加记录成功"; } else { jsonResult.Status = Model.AjaxResult.StatusValue.Error; jsonResult.Msg = @"添加记录失败"; } return(jsonResult); }
public Model.AjaxResult Like(HttpContext context, Model.AjaxResult ajax) { int channel_id = ConvertTool.ToInt(DTRequest.GetString("channel_id"), 0); if (channel_id <= 0) { return(ErrorAjaxResult(ajax, @"频道错误")); } int article_id = ConvertTool.ToInt(DTRequest.GetString("article_id"), 0); if (article_id <= 0) { return(ErrorAjaxResult(ajax, @"文章错误")); } BLL.article bllarticle = new BLL.article(); string fieldname = ReflexHelp.Name(() => new Model.article().like_count); bool issu = bllarticle.UpdateField(channel_id, article_id, string.Format("{0} = {0} + 1", fieldname)); if (!issu) { return(ErrorAjaxResult(ajax, @"点赞失败!")); } ajax.Status = Model.AjaxResult.StatusValue.Success; ajax.Msg = @"点赞成功!"; return(ajax); }
/// <summary> /// 返回响应客户端结果 图片资源时使用 /// </summary> public override void ReturnResponseResult(HttpContext context, Model.AjaxResult ajaxresultModel) { context = SetContentFormat(context); context.Response.BinaryWrite(ajaxresultModel.BinaryResource); EndResponseBeforeEvent(context); context.Response.End(); }
/// <summary> /// 给客户端返回结果 /// </summary> public virtual void ReturnResponseResult(HttpContext context, Model.AjaxResult ajaxresultModel) { context = SetContentFormat(context); dynamic dyobj = AjaxResultFormat(ajaxresultModel); context.Response.Write(OutputWriteContent(dyobj)); context.Response.End(); }
/// <summary> /// 返回响应客户端结果 Jsonp 跨域请求时使用 /// </summary> public override void ReturnResponseResult(HttpContext context, Model.AjaxResult ajaxresultModel) { context = SetContentFormat(context); dynamic dyobj = AjaxResultFormat(ajaxresultModel); string rstr = string.Format("{0}({1});", this.JsonpCallback_Name, OutputWriteContent(dyobj)); context.Response.Write(rstr); context.Response.End(); }
/// <summary> /// ajax 结果格式化 /// </summary> public virtual dynamic AjaxResultFormat(Model.AjaxResult ajaxresultModel) { return(new { Status = (int)ajaxresultModel.Status, Msg = ajaxresultModel.Msg, Url = ajaxresultModel.Url, ReturnJsonStrs = ajaxresultModel.ResultContent, }); }
/// <summary> /// 错误结果模型传递 /// </summary> /// <param name="source_model">需要转换的模型</param> /// <param name="error_msg">错误信息描述</param> /// <returns></returns> public virtual Model.AjaxResult ErrorAjaxResult(Model.AjaxResult source_model, string error_msg) { if (CheckData.IsObjectNull(source_model)) { source_model = GetInitAjaxJsonResultModel(); } source_model.Status = Model.AjaxResult.StatusValue.Error; source_model.Msg = error_msg; source_model.ResultContent = new object(); source_model.Url = string.Empty; return(source_model); }
/// <summary> /// 继承自接口: IHttpHandler 处理请求 一般情况下继承此类不需要重写此方法 /// </summary> /// <param name="context">HTTP 请求信息上下文</param> public virtual void ProcessRequest(HttpContext context) { StructureInitTool(); Model.AjaxResult jsonResult = GetInitAjaxJsonResultModel(); try { jsonResult = LogicalProcessing(context, jsonResult); } catch (Exception ex) { SystemLog.Write(ex); jsonResult.Status = Model.AjaxResult.StatusValue.Error; jsonResult.Msg = @"服务器出错了, 已记录日志...请联系管理员!"; } finally { ReturnResponseResult(context, jsonResult); } }
/// <summary> /// 逻辑处理 /// </summary> private Model.AjaxResult LogicalProcessing(HttpContext context, Model.AjaxResult jsonResult) { string action = DTRequest.GetString(ActionParameterName()); Dictionary <string, Func <HttpContext, Model.AjaxResult, Model.AjaxResult> > actionsource = ActionSource(); if (CheckData.IsSizeEmpty(actionsource)) { actionsource = new Dictionary <string, Func <HttpContext, Model.AjaxResult, Model.AjaxResult> >(); } if (!actionsource.ContainsKey(action)) { Func <HttpContext, Model.AjaxResult, Model.AjaxResult> defaultAction = DefaultActionMethod(); if (CheckData.IsObjectNull(defaultAction)) { return(ErrorAjaxResult(jsonResult, @"没有可以执行的方法")); } else { actionsource.Add(action, defaultAction); } } return(actionsource[action](context, jsonResult)); }