public ResGetUsersInfo GetUsersInfo([FromHeader] ReqGetUsersInfo req) { ResGetUsersInfo retValue = new ResGetUsersInfo(); using (var db = DbContext.GetInstance("T_USERS")) { #region 判断必填项 bool status = true; if (string.IsNullOrEmpty(req.uCode)) { retValue.FailDefalut("必填参数用户编号"); status = false; } #endregion try { if (status) { var res = db.Queryable <USERSBASE>() .Where(s => s.uCode == req.uCode) .FirstOrDefault(); UserInfo userInfo = new UserInfo(); ReqToDBGenericClass <USERSBASE, UserInfo> .ReqToDBInstance(res, userInfo); //获取用户所在团队 var team = db.Queryable <T_TEAM_MEMBERS>().Where(s => s.user_code == req.uCode).FirstOrDefault(); if (team != null) { userInfo.teamId = team.team_id; userInfo.teamName = team.team_name; userInfo.isTeamAdmin = team.is_admin; } userInfo.techList = JsonConvert.DeserializeObject <List <string> >(userInfo.techDirection); //获取文章点赞数 //获取文章点赞总数 userInfo.likeNum = db.Queryable <T_LIKE>().Where(s => s.type == LikeType.Doc.ToString()).Where("item_id in (select ID from T_ANNEX where create_user_code = " + req.uCode + ")").Count(); retValue.SuccessDefalut(userInfo, 1, "不存在该用户"); } } 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 ResGetLeaders GetLeaders([FromHeader] ReqGetLeaders req) { ResGetLeaders retValue = new ResGetLeaders(); using (var db = DbContext.GetInstance("T_USERS")) { try { if (string.IsNullOrEmpty(req.uCode)) { retValue.FailDefalut("必填参数[用户编号]"); } else { //如果有信息被设置为置顶并且根据创建时间降序 var userList = db.Queryable <USERSBASE>() .Where(s => s.techDirection.Contains(req.leaderType)) .OrderBy(s => s.followedNum, OrderByType.desc) .ToList(); //分页 0是第一页 List <leader> leaderList = new List <leader>(); foreach (var item in userList) { leader user = new leader(); ReqToDBGenericClass <USERSBASE, leader> .ReqToDBInstance(item, user); user.isFollowed = db.Queryable <T_FOLLOW_USERS>().Any(s => s.create_user_code == req.uCode && s.follow_user_code == item.uCode); var list = db.Queryable <T_USER_TAGS>().Where(s => s.create_user_code == item.uCode).Select(s => s.label).ToList(); var techList = JsonConvert.DeserializeObject <List <string> >(item.techDirection); user.tag = string.Join(";", list); user.techDirection = string.Join(";", techList); leaderList.Add(user); } var reList = leaderList.Skip((req.currentPage - 1) * req.pageSize) .Take(req.pageSize).ToList(); retValue.SuccessDefalut(reList, userList.Count); } } catch (Exception ex) { retValue.FailDefalut(ex); } } return(retValue); }
public ResGetGoods GetGoods([FromHeader] ReqGetGoods req) { ResGetGoods retValue = new ResGetGoods(); using (var db = DbContext.GetInstance("T_ANNEX")) { try { //如果有信息被设置为置顶并且根据创建时间降序 var annexList = db.Queryable <ANNEXBASE>() .Where(s => s.fileTag.Contains(req.articleType)) .OrderBy(s => s.likeNum, OrderByType.desc) .ToList(); List <goods> goods = new List <goods>(); var userList = db.Queryable <T_USERS>().ToList(); foreach (var item in annexList) { goods good = new goods(); ReqToDBGenericClass <ANNEXBASE, goods> .ReqToDBInstance(item, good); var user = userList.Where(s => s.u_code == item.createUserCode).FirstOrDefault(); if (user != null) { good.avatar = user.avatar; } goods.Add(good); } //分页 0是第一页 var reList = goods.Skip((req.currentPage - 1) * req.pageSize) .Take(req.pageSize).ToList(); retValue.SuccessDefalut(reList, annexList.Count); } catch (Exception ex) { retValue.FailDefalut(ex); } } return(retValue); }
public ResLogin Login([FromBody] ReqUsersBase user) { ResLogin retValue = new ResLogin(); using (var db = DbContext.GetInstance("T_USERS")) { try { var userInfo = db.Queryable <USERSBASE>() .Where(s => s.username == user.username) .Where(s => s.password == user.password) .FirstOrDefault(); if (userInfo == null) { retValue.FailDefalut("账号或者密码错误"); } else { My my = new My(); ReqToDBGenericClass <USERSBASE, My> .ReqToDBInstance(userInfo, my); my.techList = JsonConvert.DeserializeObject <List <string> >(my.techDirection); retValue.SuccessDefalut(my, 1, "账号或者密码错误"); } //记录登录日志 if (userInfo != null) { LogWirter.Record(LogType.Login, OpType.Login, "", "登录", 0, userInfo.createUserCode, userInfo.createUserName); } } catch (Exception ex) { retValue.FailDefalut(ex); } } return(retValue); }
public ResGetMyDocs GetMyDocs([FromHeader] ReqGetMyDocs req) { ResGetMyDocs retValue = new ResGetMyDocs(); using (var db = DbContext.GetInstance("T_ANNEX")) { #region 判断必填项 bool status = true; if (string.IsNullOrEmpty(req.uCode)) { retValue.FailDefalut("必填参数用户编号"); status = false; } #endregion try { if (status) { var list = db.Queryable <ANNEXBASE>() .Where(s => s.createUserCode == req.uCode); //内容或者标签标题包含 搜索条件则输出 if (!string.IsNullOrEmpty(req.content)) { list.Where(s => s.content.Contains(req.content) || s.fileTag.Contains(req.content) || s.fileName.Contains(req.content)); } int pageNum = 0; var resList = list.OrderBy(s => s.createTime, OrderByType.desc).ToPageList(req.currentPage, req.pageSize, ref pageNum); List <newAnnexBase> newRes = new List <newAnnexBase>(); string avatar = string.Empty; var user = db.Queryable <T_USERS>().Where(u => u.u_code == req.uCode).FirstOrDefault(); if (user != null) { avatar = user.avatar; } foreach (var item in resList) { newAnnexBase annex = new newAnnexBase(); ReqToDBGenericClass <ANNEXBASE, newAnnexBase> .ReqToDBInstance(item, annex); annex.fileTagList = JsonConvert.DeserializeObject <List <string> >(item.fileTag); annex.avatar = avatar; annex.isLike = db.Queryable <T_LIKE>() .Any(s => s.item_id == item.ID && s.create_user_code == req.uCode && s.type == LikeType.Doc.ToString()); newRes.Add(annex); } retValue.SuccessDefalut(newRes, pageNum); } } catch (Exception ex) { retValue.FailDefalut(ex); } } return(retValue); }