public List <dto_User> Search(string Name) { List <dto_User> res = new List <dto_User>(); using (PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, _settings.ADDomain)) { UserPrincipal UserPrincipal = new UserPrincipal(principalContext); if (!string.IsNullOrEmpty(Name)) { UserPrincipal.SamAccountName = Name; } PrincipalSearcher search = new PrincipalSearcher(UserPrincipal); foreach (UserPrincipal result in search.FindAll()) { dto_User user = new dto_User(); dtoHelper dtoHelper = new dtoHelper(); dtoHelper.FillBase(user); user.Name = result.Name; user.NameAr = result.SamAccountName; user.NameEn = result.SamAccountName; user.Email = result.EmailAddress; user.isActivated = true; user.ActivationStartDate = DateTime.Now; user.IsDeleted = false; user.isAD = true; res.Add(user); //if (result.SamAccountName.ToUpper().Contains("AABDELHAYD")) //{ //} } return(res); } }
/// <summary> /// 根据UserId查询User /// </summary> /// <param name="userId"></param> /// <returns></returns> public static dto_User GetUser(int userId) { dto_User tempresult = null; T_User u = null; string key = RedisHelper.GetEasyZyRedisKey(Const.CacheCatalog.User, userId.ToString()); using (var client = RedisHelper.Instance.GetRedisClient(Const.CacheCatalog.User.ToString())) { if (client != null) { tempresult = client.Get <dto_User>(key); if (tempresult == null) { u = D_User.GetUser(userId); if (u != null) { tempresult = TransUserToDtoUser(u); client.Set(key, tempresult, ts); } } } } return(tempresult); }
public IActionResult ForgotPassword([FromBody] dto_User model) { GenericResponse res = new GenericResponse(); res.FillSuccess(); if (model != null && !string.IsNullOrEmpty(model.Email)) { var olduser = _service_account.GetUser(model.Email); if (olduser != null) { _emailHelper.AddToAddress(model.Email); _emailHelper.Subject = "Reset Password"; _emailHelper.Body = "Kindly find your password as following : " + olduser.Password; _emailHelper.SendMail(); } else { res.FillError(); } } else { res.FillError(); } return(Ok(res)); }
private static dto_User TransUserToDtoUser(T_User u) { dto_User result = new dto_User() { Id = u.Id, UserName = u.UserName, Psd = u.Psd, Mobile = u.Mobile, CreateDate = u.CreateDate, FirstLoginDate = u.FirstLoginDate, TrueName = u.TrueName, ZyPrice = u.ZyPrice, ZyPsd = u.ZyPsd, ProvinceId = u.ProvinceId, CityId = u.CityId, DistrictId = u.DistrictId, SchoolId = u.SchoolId, GradeId = u.GradeId, ClassId = u.ClassId }; string pName = ""; bool b = Const.Provinces.TryGetValue(result.ProvinceId, out pName); result.ProvinceName = pName == null ? "" : pName; result.CityName = result.CityId == 0 ? "" : D_BaseRedis.GetCities(result.ProvinceId).Find(a => a.CityId == result.CityId).CityName; result.DistrictName = result.DistrictId == 0 ? "" : D_BaseRedis.GetDistricts(result.CityId).Find(a => a.DistrictId == result.DistrictId).DistrictName; result.SchoolName = result.SchoolId == 0 ? "" : D_BaseRedis.GetSchool(result.SchoolId).SchoolName; string gName = ""; Const.Grades.TryGetValue(result.GradeId, out gName); result.GradeName = gName == null ? "" : gName; result.ClassName = result.ClassId == 0 ? "" : result.ClassId + "班"; return(result); }
public ActionResult GetSubmitedZy(int pageIndex, int pageSize) { int totalCount = 0; List <dto_Zy> list = null; List <int> ids = B_Answer.GetSubmitedZyIds(UserId, pageIndex, pageSize, out totalCount); if (ids != null) { list = new List <dto_Zy>(); ids.ForEach(a => { list.Add(B_ZyRedis.GetZy(a)); }); } if (list != null) { foreach (var l in list) { //隐藏真实Id l.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Zy, l.Id); dto_User u = B_UserRedis.GetUser(l.UserId); l.UserName = u.UserName; l.TrueName = u.TrueName; l.Id = 0; } } ViewBag.ZyList = list; ViewBag.PageCount = Util.GetTotalPageCount(totalCount, pageSize); return(PartialView()); }
private void emptyUser(dto_User user) { user.Password = string.Empty; user.Image = string.Empty; if (user.Groups != null) { foreach (var item in user.Groups) { item.Users = null; if (item.Privilliges != null) { foreach (var p in item.Privilliges) { p.Users = null; p.Groups = null; } } } } if (user.Privilliges != null) { foreach (var item in user.Privilliges) { item.Groups = null; item.Users = null; } } }
/// <summary> /// 生成统计信息 /// </summary> /// <param name="answer"></param> public static void GenerateAnalyze(T_Answer answer) { Task.Run(() => { dto_User u = null; if (answer.StudentId == 0) { u = new dto_User() { SchoolId = 0, GradeId = 0, ClassId = 0, TrueName = "试用用户" }; } else { u = B_UserRedis.GetUser(answer.StudentId); } IncreaseClassSubmitCount(answer.ZyId, u); var ansl = JsonConvert.DeserializeObject <List <dto_UserAnswer> >(answer.AnswerJson); InsertStudentPoint(answer.ZyId, answer.StudentId, answer.CreateDate, ansl, u); IncreaseQuesCorrectCount(answer.ZyId, ansl, u); IncreaseOptionSelectCount(answer.ZyId, ansl, u); }); }
/// <summary> /// 获取已提交作业 /// </summary> /// <param name="lastId"></param> /// <param name="count"></param> /// <returns></returns> public ActionResult GetSubmitedZy(long lastId, int count) { int last = lastId == 0 ? 99999999 : IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Zy, lastId); List <dto_Zy> list = null; List <int> ids = B_Answer.GetSubmitedZyIds(UserId, last, count); if (ids != null) { list = new List <dto_Zy>(); ids.ForEach(a => { list.Add(B_ZyRedis.GetZy(a)); }); } if (list != null) { foreach (var l in list) { //隐藏真实Id l.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Zy, l.Id); dto_User u = B_UserRedis.GetUser(l.UserId); l.UserName = u.UserName; l.TrueName = u.TrueName; l.Id = 0; } } ViewBag.ZyList = list; return(PartialView()); }
public ActionResult GetRelatedUserZy(int pageIndex, int pageSize) { int totalCount = 0; int[] RUsers = B_User.GetRelatedUser(UserId); List <dto_Zy> list = B_Zy.GetZyList(RUsers, pageIndex, pageSize, out totalCount); if (list != null) { List <int> ids = B_Answer.GetSubmitedZyIds(UserId, list.Select(a => a.Id).ToArray()); foreach (var l in list) { l.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Zy, l.Id); string subName = ""; Const.Subjects.TryGetValue(l.SubjectId, out subName); l.SubjectName = subName; l.TypeName = l.Type == 0 ? "题库" : "自传"; dto_User u = B_UserRedis.GetUser(l.UserId); l.UserName = u.UserName; l.TrueName = u.TrueName; l.Submited = ids == null ? false : ids.Exists(a => a == l.Id); //隐藏真实Id l.Id = 0; } } ViewBag.RelateUserCount = RUsers == null ? 0 : RUsers.Length; ViewBag.ZyList = list; ViewBag.PageCount = Util.GetTotalPageCount(totalCount, pageSize); return(PartialView()); }
public IActionResult update([FromBody] dto_User user) { GenericResponse res = new GenericResponse(); res.FillSuccess(); _profileService.update(user); return(Ok(res)); }
/// <summary> /// 本班同学 /// </summary> /// <returns></returns> public ActionResult MyClassmates() { dto_User u = B_UserRedis.GetUser(UserId); List <T_User> list = B_User.GetClassmates(u.SchoolId, u.GradeId, u.ClassId); ViewBag.List = list; return(PartialView()); }
// DELETE api/<controller>/5 public IActionResult Delete([FromBody] dto_User Model) { GenericResponse response = new GenericResponse(); response.FillSuccess(); _service_User.Remove(Model); response.data = Model; return(Ok(response)); }
/// <summary> /// 作业班级提交数量 /// </summary> /// <param name="zyId"></param> /// <param name="u"></param> private static void IncreaseClassSubmitCount(int zyId, dto_User u) { MySqlHelper.ExecuteNonQuery(Util.GetConnectString(AnalyzeConnString), "insert into T_ClassSubmitCount(ZyId, SchoolId, GradeId, ClassId, SubmitCount) values (@ZyId, @SchoolId, @GradeId, @ClassId, 1) on duplicate key update SubmitCount = SubmitCount + 1", "@ZyId".ToInt32InPara(zyId), "@SchoolId".ToInt32InPara(u.SchoolId), "@GradeId".ToInt32InPara(u.GradeId), "@ClassId".ToInt32InPara(u.ClassId) ); }
public ActionResult GetUserInfo() { dto_User UserInfo = B_UserRedis.GetUser(UserId); ViewBag.UserInfo = UserInfo; if (UserInfo.SchoolId == 0) { ViewBag.Provinces = Const.Provinces; } ViewBag.Grades = Const.Grades; return(PartialView()); }
public static void UpdateFirstLoginDate(int userId, DateTime firstLoginDate) { dto_User tempresult = null; string key = RedisHelper.GetEasyZyRedisKey(CacheCatalog.User, userId.ToString()); using (var client = RedisHelper.Instance.GetRedisClient(CacheCatalog.User.ToString())) { if (client != null) { tempresult = client.Get <dto_User>(key); if (tempresult != null) { tempresult.FirstLoginDate = firstLoginDate; client.Set(key, tempresult, ts); } } } }
/// <summary> /// 修改学校信息,如果已经被改过,则不能重复修改 /// </summary> /// <param name="userClass"></param> /// <returns></returns> public int UpdateUserSchool(int provinceId, int cityId, int districtId, int schoolId) { if (provinceId == 0 || cityId == 0 || districtId == 0 || schoolId == 0) { return(1); } dto_User du = B_UserRedis.GetUser(UserId); if (du.SchoolId != 0) { return(1); } if (B_User.UpdateSchool(UserId, provinceId, cityId, districtId, schoolId)) { B_UserRedis.ReloadUserCache(UserId); return(0); } return(1); }
public static void ReloadUserCache(int userId) { dto_User result = null; T_User tmp = B_User.GetUser(userId); if (tmp == null) { return; } result = TransUserToDtoUser(tmp); string key = RedisHelper.GetEasyZyRedisKey(CacheCatalog.User, userId.ToString()); using (var client = RedisHelper.Instance.GetRedisClient(CacheCatalog.User.ToString())) { if (client != null) { client.Set(key, result, ts); } } }
public JsonResult AddModifyRequest(int schoolId, string reason) { dto_User u = B_UserRedis.GetUser(UserId); dto_ModifyRequest mr = new dto_ModifyRequest() { UserId = UserId, FromSchoolId = u.SchoolId, ToSchoolId = schoolId, Reason = reason, CreateDate = DateTime.Now, Status = 0 }; int i = B_User.AddModifyRequest(mr); if (i != 0) { mr.Id = i; mr.CreateDateStr = mr.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"); mr.FromSchoolName = B_BaseRedis.GetSchool(mr.FromSchoolId).SchoolName; mr.ToSchoolName = B_BaseRedis.GetSchool(mr.ToSchoolId).SchoolName; return(Json(mr)); } return(null); }
public static void UpdateClass(int userId, int gradeId, string gradeName, int classId, string className) { dto_User tempresult = null; string key = RedisHelper.GetEasyZyRedisKey(CacheCatalog.User, userId.ToString()); using (var client = RedisHelper.Instance.GetRedisClient(CacheCatalog.User.ToString())) { if (client != null) { tempresult = client.Get <dto_User>(key); if (tempresult != null) { tempresult.GradeId = gradeId; tempresult.GradeName = gradeName; tempresult.ClassId = classId; tempresult.ClassName = className; client.Set(key, tempresult, ts); } } } }
// POST api/<controller> public IActionResult Create([FromBody] dto_User Model) { GenericResponse response = new GenericResponse(); if (ModelState.IsValid) { response.FillSuccess(); FillBase(Model); if (_service_account.validate(Model)) { _service_User.CreateOREdit(Model); response.data = Model; } else { response.FillError("Already Exist"); } } else { response.FillError(); } return(Ok(response)); }
/// <summary> /// 学生作业得分 /// </summary> /// <param name="zyId"></param> /// <param name="studentId"></param> /// <param name="submitDate"></param> /// <param name="ansl"></param> /// <param name="u"></param> private static void InsertStudentPoint(int zyId, int studentId, DateTime submitDate, List <dto_UserAnswer> ansl, dto_User u) { int Score = (ansl.Count(ans => Const.OBJECTIVE_QUES_TYPES.Contains(ans.PTypeId) && ans.Answer == ans.CAnswer)); MySqlHelper.ExecuteNonQuery(Util.GetConnectString(AnalyzeConnString), "insert into T_StudentPoint(ZyId, StudentId, SchoolId, GradeId, ClassId, SubmitDate, Score) values (@ZyId, @StudentId, @SchoolId, @GradeId, @ClassId, @SubmitDate, @Score)", "@ZyId".ToInt32InPara(zyId), "@StudentId".ToInt32InPara(studentId), "@SchoolId".ToInt32InPara(u.SchoolId), "@GradeId".ToInt32InPara(u.GradeId), "@ClassId".ToInt32InPara(u.ClassId), "@SubmitDate".ToDateTimeInPara(submitDate), "@Score".ToInt32InPara(Score) ); }
public IActionResult Login([FromBody] dto_User input) { GenericResponse _res = new GenericResponse(); _res.FillSuccess(); if (input != null) { var user = _service_account.GetUser(input.Email); if (user != null) { if (user.isAD) { var valid = _helper_activeDirectory.Validate(input.Email, input.Password); if (valid) { user = _service_account.loginAD(input.Email); } else { user = null; _res.FillError("User NotFound"); } } else if (input.IsThirdParty) { user = _service_account.login(input.Email); } else { user = _service_account.login(input.Email, input.Password); } } else { if (input.IsThirdParty) { FillBase(input); input.ActivationStartDate = DateTime.Now; input.isActivated = true; _service_account.register(input); user = _service_account.login(input.Email); } else { _res.FillError("User NotFound"); } } if (user != null) { if (user.isActivated && user.ActivationStartDate.HasValue && user.ActivationStartDate.Value <= DateTime.Now && (user.ActivationEndDate.HasValue == false || user.ActivationEndDate <= DateTime.Now) ) { UserTokenModel model = new UserTokenModel(); model.IsEnglish = true; emptyUser(user); model.User = user; string token = GenerateToken_HS256(model); //string token = GenerateToken_RS256(user); //string Decoded = decodeToken_RS256(token); _res.data = token; } else { _res.FillError("User is not activated"); } return(Ok(_res)); } else { _res.FillError("User NotFound"); return(Ok(_res)); } } else { _res.FillError("User NotFound"); return(Ok(_res)); } }
/// <summary> /// 试题选项选中数 /// </summary> /// <param name="zyId"></param> /// <param name="ansl"></param> /// <param name="u"></param> private static void IncreaseOptionSelectCount(int zyId, List <dto_UserAnswer> ansl, dto_User u) { List <string> ObjectiveQuesNum = new List <string>(); List <dto_ZyQuestion> ql = JsonConvert.DeserializeObject <List <dto_ZyQuestion> >(B_ZyRedis.GetQdbZyQuesJson(zyId)); int s = 0, t = 0, lastPQId = 0; if (ql != null) { foreach (var q in ql) { if (Const.OBJECTIVE_QUES_TYPES.Contains(q.PTypeId)) { if (q.PQId != lastPQId) { s += 1; t = 1; lastPQId = q.PQId; } else { t += 1; } if (q.PQId == q.QId) { ObjectiveQuesNum.Add(s.ToString()); } else { ObjectiveQuesNum.Add(string.Concat(s, "-", t)); } } } } string sql = "insert into T_OptionSelectCount(ZyId, QuesNum, QuesNumTip, SchoolId, GradeId, ClassId, OptionA, OptionB, OptionC, OptionD) values "; for (int i = 0; i < ObjectiveQuesNum.Count; i++) { var oansl = ansl.FindAll(a => Const.OBJECTIVE_QUES_TYPES.Contains(a.PTypeId)); sql += string.Format("({0}, {1}, '{2}', {3}, {4}, {5}, {6}, {7}, {8}, {9}),", zyId, i + 1, ObjectiveQuesNum[i], u.SchoolId, u.GradeId, u.ClassId, (oansl[i].Answer.Contains("A") ? 1 : 0), (oansl[i].Answer.Contains("B") ? 1 : 0), (oansl[i].Answer.Contains("C") ? 1 : 0), (oansl[i].Answer.Contains("D") ? 1 : 0)); } sql = sql.Substring(0, sql.Length - 1); sql += " on duplicate key update OptionA = OptionA + VALUES(OptionA), OptionB = OptionB + VALUES(OptionB), OptionC = OptionC + VALUES(OptionC), OptionD = OptionD + VALUES(OptionD)"; MySqlHelper.ExecuteNonQuery(Util.GetConnectString(AnalyzeConnString), sql); }