public ResUsersBase Add([FromBody] ReqUsersBase user) { ResUsersBase retValue = new ResUsersBase(); using (var db = DbContext.GetInstance("T_USERS")) { try { //设置创建时间 user.createTime = DateTime.Now; var isExist = db.Queryable <USERSBASE>() .Any(s => s.username == user.username); if (!isExist) { db.Insert(user); retValue.SuccessDefalut("创建新用户成功!", 1); LogWirter.Record(LogType.Admin, OpType.Add, "", "创建用户", Convert.ToInt32(user.uCode), user.createUserCode, user.createUserName); } else { retValue.FailDefalut("用户已存在,请更新账号!"); } } catch (Exception ex) { retValue.FailDefalut(ex); } } return(retValue); }
public ResUsersBase UpdateAvatar([FromBody] ReqUsersBase user) { ResUsersBase retValue = new ResUsersBase(); using (var db = DbContext.GetInstance("T_USERS")) { try { //设置禁止更新列 db.AddDisableUpdateColumns("username", "password", "is_admin", "follow_num", "followed_num", "ID", "scores", "u_code", "create_time"); bool isIDExist = db.Queryable <USERSBASE>() .Any(s => s.uCode == user.uCode); if (isIDExist) { #region 验证必填信息及其格式 bool status = true; //登录后将获取的信息存在本地 然后用于请求 if (string.IsNullOrEmpty(user.avatar)) { retValue.FailDefalut("请填写正确的头像地址"); status = false; } #endregion if (status) { var newUser = db.Queryable <USERSBASE>().Where(s => s.uCode == user.uCode).FirstOrDefault(); if (newUser != null) { user.ID = newUser.ID; ReqToDBGenericClass <ReqUsersBase, USERSBASE> .ReqToDBInstance(user, newUser); db.Update(newUser); retValue.SuccessDefalut("更新成功!", 1); LogWirter.Record(LogType.Login, OpType.Update, "信息", "更改昵称,编辑", Convert.ToInt32(user.uCode), user.createUserCode, user.createUserName); } } } else { retValue.FailDefalut("不存在该用户ID"); } } catch (Exception ex) { retValue.FailDefalut(ex); } } return(retValue); }
public ResUsersBase InsertOrUpdate([FromBody] ReqUsersBase user) { ResUsersBase retValue = new ResUsersBase(); using (var db = DbContext.GetInstance("T_USERS")) { try { //设置创建时间 user.createTime = DateTime.Now; db.InsertOrUpdate(user); retValue.SuccessDefalut(1); } catch (Exception ex) { retValue.FailDefalut(ex); } } return(retValue); }
public ResUsersBase UpdatePassword([FromBody] ReqUsersBase user) { ResUsersBase retValue = new ResUsersBase(); using (var db = DbContext.GetInstance("T_USERS")) { bool status = true; if (string.IsNullOrEmpty(user.phoneNum)) { retValue.FailDefalut("请填写你的手机号"); status = false; } else if (string.IsNullOrEmpty(user.uCode)) { retValue.FailDefalut("填写你的学号"); status = false; } else if (string.IsNullOrEmpty(user.idCard)) { retValue.FailDefalut("请填写你的身份证号码"); status = false; } if (status) { try { //设置禁止更新列 db.AddDisableUpdateColumns("username", "is_admin"); var isExist = db.Queryable <USERSBASE>() .Any(s => s.uCode == user.uCode); if (isExist) { #region 验证必填信息及其格式 if (string.IsNullOrEmpty(user.password)) { retValue.FailDefalut("请填写你的新密码!"); } #endregion var student = db.Queryable <USERSBASE>().Where(u => u.uCode == user.uCode).FirstOrDefault(); if (student != null) { if (student.idCard != user.idCard || student.phoneNum != user.phoneNum) { retValue.FailDefalut("手机号或者身份证与学号不对应"); } else { db.Update <USERSBASE>(new { password = user.password }, it => it.phoneNum == user.phoneNum); //只更新密码列 retValue.SuccessDefalut("更新成功!", 1); var info = db.Queryable <USERSBASE>().Where(s => s.phoneNum == user.phoneNum).FirstOrDefault(); LogWirter.Record(LogType.Login, OpType.Update, "手机号码", "通过手机号更新密码", Convert.ToInt32(info.uCode), info.createUserCode, info.createUserName); } } else { retValue.FailDefalut("不存在该学号"); } } else { retValue.FailDefalut("不存在该学号"); } } catch (Exception ex) { retValue.FailDefalut(ex); } } } return(retValue); }