ASP.NET MVC API 接口验证的示例代码(3)

/// <summary> /// ApiResultModel /// 统一回传格式实体 /// /// 修改纪录 /// /// 2016-10-31 版本:1.0 宋彪 创建文件。 /// /// <author> /// <name>宋彪</name> /// <date>2016-10-31</date> /// </author> /// </summary> public class ApiResultModel { public HttpStatusCode Status { get; set; } //public JsonResult<T> Data { get; set; } public object Data { get; set; } public string ErrorMessage { get; set; } }

8、留言相关接口

/// <summary> /// MessageBookController /// 留言相关接口 /// /// 修改纪录 /// /// 2016-10-31 版本:1.0 宋彪 创建文件。 /// /// <author> /// <name>宋彪</name> /// <date>2016-10-31</date> /// </author> /// </summary> [ApiAuthFilter] public class CustomerMessageController : ApiController { /// <summary> /// 保存单号留言信息 /// </summary> /// <param></param> /// <returns></returns> [HttpPost] //[AllowAnonymous] 不需要验证的就加这个标签 public IHttpActionResult Add([FromBody]MsgbookCusEntity messageBook) { BaseResult baseResult = new BaseResult(); if (string.IsNullOrWhiteSpace(messageBook.SystemFrom)) { baseResult.Status = false; baseResult.StatusMessage = "SystemFrom参数不可为空"; } else { try { MsgbookCusManager manager = new MsgbookCusManager(APIOperateContext.BusinessDbHelper, APIOperateContext.Current.UserInfo); MsgbookCusEntity model = new MsgbookCusEntity(); model.Id = Guid.NewGuid().ToString("N"); model.Message = messageBook.Message; model.SendEmail = messageBook.SendEmail; model.SendTelephone = messageBook.SendTelephone; model.Message = messageBook.Message; model.BillCode = messageBook.BillCode; model.SystemFrom = messageBook.SystemFrom; model.DeletionStateCode = 0; manager.Add(model, false, false); baseResult.Status = true; baseResult.StatusMessage = "添加成功。"; } catch (Exception ex) { NLogHelper.Warn(ex, "CustomerMessageController AddBillMessage 异常"); baseResult.Status = false; baseResult.StatusMessage = "异常:" + ex.Message; } } return Ok(baseResult); } /// <summary> /// 获取某个单号的留言 /// </summary> /// <param></param> /// <returns></returns> [HttpGet] public IHttpActionResult GetList(string billCode) { JsonResult<List<MsgbookCusEntity>> jsonResult = new JsonResult<List<MsgbookCusEntity>>(); try { MsgbookCusManager manager = new MsgbookCusManager(APIOperateContext.BusinessDbHelper, APIOperateContext.Current.UserInfo); List<MsgbookCusEntity> list = new List<MsgbookCusEntity>(); list = manager.GetList<MsgbookCusEntity>(new KeyValuePair<string, object>(MsgbookCusEntity.FieldBillCode, billCode) , new KeyValuePair<string, object>(MsgbookCusEntity.FieldDeletionStateCode, 0)); jsonResult.Status = true; jsonResult.RecordCount = list.Count; jsonResult.Data = list; jsonResult.StatusMessage = "获取成功"; } catch (Exception ex) { NLogHelper.Warn(ex, "CustomerMessageController AddBillMessage 异常"); jsonResult.Status = false; jsonResult.StatusMessage = "异常:" + ex.Message; } return Ok(jsonResult); } }

9、接口调用方法

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdpwdw.html