/// <summary> /// 获取读者信息 /// </summary> /// <param name="userID">用户 ID</param> /// <returns>信息字典{ 信息类型, 信息内容 }</returns> public ReaderInfoModel GetReaderInfo(int userID) { ReaderInfoModel info = null; if (userID < 10000) { throw new Exception("Permission Denied"); } if (GlobalFunc.FindPersonById(userID)) { try { info = DbContext.DBstatic.Queryable <ReaderInfo>() .Select(f => new ReaderInfoModel { ID = f.ID, Contact = f.Contact, Name = f.Name, Gender = f.Gender, Credit_Score = f.Credit_Score }) .Where(it => it.ID == userID).Single(); } catch { throw new Exception($"Failed to query user information with id: {userID}"); } } return(info); }
public IActionResult ModInfo(string contact = null, [FromQuery] string name = null, [FromQuery] string gender = null) { name = GlobalFunc.MyUrlDeCode(name, Encoding.UTF8); gender = GlobalFunc.MyUrlDeCode(gender, Encoding.UTF8); var auth = HttpContext.AuthenticateAsync(); var id = Convert.ToInt32(auth.Result.Principal.Claims.First(t => t.Type.Equals(ClaimTypes.NameIdentifier)) ?.Value); if (id >= 10000) { var newInfo = new ReaderInfoModel { ID = id, Name = name, Contact = contact, Gender = gender }; try { rd.ReaderModifyInfo(newInfo); } catch (Exception ex) { return(Ok(new { error = ex.Message })); } } else if (id < 10000 && id >= 1) { var newInfo = new AdminInfoModel { ID = id, Name = name, Contact = contact, Gender = gender }; try { ad.AdminModifyInfo(newInfo); } catch (Exception ex) { return(Ok(new { error = ex.Message })); } } else { return(Ok(new { error = "Invalid Id" })); } return(Ok(GlobalFunc.GetBasicInfo(id))); }
/// <summary> /// 获取读者信息 /// </summary> /// <param name="userID">用户 ID</param> /// <returns>用户信息模型</returns> public ReaderInfoModel GetReaderInfo(int userID) { ReaderInfoModel info = null; if (GlobalFunc.FindPersonById(userID)) { info = DbContext.DBstatic.Queryable <ReaderInfo>() .Select(f => new ReaderInfoModel { ID = f.ID, Contact = f.Contact, Name = f.Name, Gender = f.Gender, Credit_Score = f.Credit_Score }) .Where(it => it.ID == userID).Single(); } return(info); }
/// <summary> /// 修改读者信息 /// </summary> /// <param name="mod"></param> /// <exception cref="MySqlException">更新失败</exception> /// <exception cref="Exception">输入错误</exception> public void ReaderModifyInfo(ReaderInfoModel mod) { try { GlobalFunc.InfoCheck(mod, mod.Contact != null); } catch (Exception ex) { throw ex; } if (mod.ID < 10000) { throw new Exception("Permission Denied"); } ReaderInfoModel tmpDic; try { tmpDic = GetReaderInfo(mod.ID); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return; } tmpDic.UpdateInfo(mod); var newInfo = new ReaderInfo().UpdateInfo(tmpDic); try { DbContext.DBstatic.Updateable(newInfo).IgnoreColumns(true, ignoreAllDefaultValue: true) .ExecuteCommand(); } catch (MySqlException ex) { throw ex; } catch (Exception ex) { throw ex; } }
/// <summary> /// 修改读者信息 /// </summary> /// <param name="mod"></param> /// <exception cref="MySqlException">更新失败</exception> public void ReaderModifyInfo(ReaderInfoModel mod) { var tmpDic = GetReaderInfo(mod.ID); tmpDic.UpdateInfo(mod); var newInfo = new ReaderInfo().UpdateInfo(tmpDic); try { DbContext.DBstatic.Updateable(newInfo).IgnoreColumns(true, ignoreAllDefaultValue: true) .ExecuteCommand(); } catch (MySqlException ex) { throw ex; } catch (Exception ex) { throw ex; } }