public static string Read(int ArrID) { using (dbDataContext db = new HsBusiness.dbDataContext()) { if (Common.TCContext.Current.OnlineUserID != "") { var UserID = Convert.ToInt32(Common.TCContext.Current.OnlineUserID);//用户ID var list = db.ArrRead.Where(x => x.ArrID == ArrID && x.UserID == UserID).FirstOrDefault(); if (list == null) { ArrRead read = new ArrRead(); read.UserID = UserID; read.ArrID = ArrID; read.IsRead = 1; db.ArrRead.InsertOnSubmit(read); } else { list.IsRead = 1; } db.SubmitChanges(); return(JsonConvert.SerializeObject(new { state = 1, msg = "请求成功" })); } return(JsonConvert.SerializeObject(new { state = 0, msg = "已读出错,请重新登录" })); } }
public IHttpActionResult Read([FromBody] RequestModel req) { try { using (dbDataContext db = new dbDataContext()) { // 真实的参数 var parameters = Common.AesDecryp.GetAesDecryp(req.data, req.secret); //项目ID var ArrID = Convert.ToInt32(parameters["ArrID"]); var UserID = Convert.ToInt32(parameters["UserID"]); var arr = db.Arrears.Where(x => x.ID == ArrID).FirstOrDefault(); var user = db.Users.Where(x => x.ID == UserID).FirstOrDefault(); if (user != null) { if (arr != null) { var model = db.ArrRead.Where(x => x.ArrID == arr.ID && x.UserID == user.ID).FirstOrDefault(); if (model == null)//添加已读记录 { ArrRead read = new ArrRead(); read.UserID = user.ID; read.ArrID = arr.ID; read.IsRead = 1; db.ArrRead.InsertOnSubmit(read); } else//修改已读记录 { model.IsRead = 1; } db.SubmitChanges(); return(Json(new { state = 1, msg = "请求成功" })); } return(Json(new { state = 0, msg = "小余额不存在" })); } return(Json(new { state = 0, msg = "用户不存在" })); } } catch (Exception ex) { throw ex; } }