public async Task <MessageModel <string> > Put([FromBody] sysUserInfo sysUserInfo) { var data = new MessageModel <string>(); if (sysUserInfo != null && sysUserInfo.uID > 0) { if (sysUserInfo.RID > 0) { var usrerole = await _userRoleServices.Query(d => d.UserId == sysUserInfo.uID && d.RoleId == sysUserInfo.RID); if (usrerole.Count == 0) { await _userRoleServices.Add(new UserRole(sysUserInfo.uID, sysUserInfo.RID)); } } data.success = await _sysUserInfoServices.Update(sysUserInfo); if (data.success) { data.msg = "更新成功"; data.response = sysUserInfo?.uID.ObjToString(); } } return(data); }
public async Task <object> exampleLogin(sysUserInfo sysUserInfo) { try { //do transaction if (string.IsNullOrEmpty(sysUserInfo.LoginName) || string.IsNullOrEmpty(sysUserInfo.LoginPWD)) { return(ReplyCode.badRequest(ErrorCode.账号密码错误)); } sysUserInfo.LoginPWD = MD5Helper.MD5Encrypt32(sysUserInfo.LoginPWD); var user = await service.LoginAsync(sysUserInfo); if (user != null) { return(ReplyCode.success(new { token = generatorToken(user, "Admin") })); } else { return(ReplyCode.badRequest(ErrorCode.账号密码错误)); } } catch (Exception e) { // if error,unify to handle return(ReplyCode.errorRequest(e).ToJsonResult()); } }
public ActionResult add(UserInfoAdd model) { if (ModelState.IsValid == false) { return(WriteError("验证失败")); } try { sysUserInfo user = new sysUserInfo() { uLoginName = model.uLoginName, uStatus = model.uStatus, uGender = model.uGender, uEmail = model.uEmail, uRealName = model.uRealName, uMobile = model.uMobile, uLoginPWD = Kits.MD5Entry("123456"), uUpdateTime = DateTime.Now, uCreateID = UserMgr.GetCurrentUserInfo().uID, uCreateTime = DateTime.Now, uCompanyID = model.uCompanyID, uDepID = model.uDepID, uWorkGroupID = model.uWorkGroupID }; _userinfoSer.Add(user); _userinfoSer.SaveChanges(); return(WriteSuccess("新增成功")); } catch (Exception ex) { return(WriteError(ex)); } }
public async Task <MessageModel <string> > Post(sysUserInfo sysUserInfo) { var data = new MessageModel <string>(); sysUserInfo.uLoginPWD = MD5Helper.MD5Encrypt32(sysUserInfo.uLoginPWD); sysUserInfo.uRemark = _user.Name; var sysuser = await _sysUserInfoServices.Query(a => a.uLoginName == sysUserInfo.uLoginName); if (sysuser.Count > 0) { data.success = false; data.msg = "用户已存在"; } else { var id = await _sysUserInfoServices.Add(sysUserInfo); data.success = id > 0; data.response = id.ObjToString(); data.msg = "添加成功"; } return(data); }
public ActionResult DeleteConfirmed(int id) { sysUserInfo sysUserInfo = db.sysUserInfo.Find(id); db.sysUserInfo.Remove(sysUserInfo); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "uID,uLoginName,uLoginPWD,uRealName,uTelphone,uMobile,uEmial,uQQ,uGender,uStatus,uCompanyID,uDepID,uWorkGroupID,uRemark,uCreatorID,uCreateTime,uUpdateID,uUpdateTime")] sysUserInfo sysUserInfo) { if (ModelState.IsValid) { db.Entry(sysUserInfo).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.uCompanyID = new SelectList(db.sysOrganStruct, "osID", "osName", sysUserInfo.uCompanyID); ViewBag.uDepID = new SelectList(db.sysOrganStruct, "osID", "osName", sysUserInfo.uDepID); ViewBag.uWorkGroupID = new SelectList(db.sysOrganStruct, "osID", "osName", sysUserInfo.uWorkGroupID); return(View(sysUserInfo)); }
public async Task <MessageModel <string> > Put([FromBody] sysUserInfo sysUserInfo) { // 这里使用事务处理 var data = new MessageModel <string>(); try { _unitOfWork.BeginTran(); if (sysUserInfo != null && sysUserInfo.uID > 0) { if (sysUserInfo.RIDs.Count > 0) { // 无论 Update Or Add , 先删除当前用户的全部 U_R 关系 var usreroles = (await _userRoleServices.Query(d => d.UserId == sysUserInfo.uID)).Select(d => d.Id.ToString()).ToArray(); if (usreroles.Count() > 0) { var isAllDeleted = await _userRoleServices.DeleteByIds(usreroles); } // 然后再执行添加操作 var userRolsAdd = new List <UserRole>(); sysUserInfo.RIDs.ForEach(rid => { userRolsAdd.Add(new UserRole(sysUserInfo.uID, rid)); }); await _userRoleServices.Add(userRolsAdd); } data.success = await _sysUserInfoServices.Update(sysUserInfo); _unitOfWork.CommitTran(); if (data.success) { data.msg = "更新成功"; data.response = sysUserInfo?.uID.ObjToString(); } } } catch (Exception e) { _unitOfWork.RollbackTran(); _logger.LogError(e, e.Message); } return(data); }
// GET: sysUserInfoes/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } sysUserInfo sysUserInfo = db.sysUserInfo.Find(id); if (sysUserInfo == null) { return(HttpNotFound()); } return(View(sysUserInfo)); }
public async Task <MessageModel <string> > Post([FromBody] sysUserInfo sysUserInfo) { var data = new MessageModel <string>(); var id = await _sysUserInfoServices.Add(sysUserInfo); data.success = id > 0; if (data.success) { data.response = id.ObjToString(); data.msg = "添加成功"; } return(data); }
public ActionResult Add(sysUserInfo model) { if (model != null) { model.uCreateTime = DateTime.Now; model.uLastErrTime = DateTime.Now; model.uUpdateTime = DateTime.Now; UserInfoService.Add(model); UserInfoService.SaverChanges(); return(Content("<script type='text/javascript'>alert('恭喜!添加成功└(^o^)┘!');window.parent.location.reload();parent.layer.close(index);</script>")); } else { return(Content("<script type='text/javascript'>alert('好像哪里出错 了,咋办 ╮(╯_╰)╭!');;</script>")); } }
public async Task <MessageModel <string> > Edit(sysUserInfo sysUserInfo) { var data = new MessageModel <string>(); //var userDetail = await _sysUserInfoServices.QueryById(sysUserInfo.uID); //userDetail.uPhoto = sysUserInfo.uPhoto; //userDetail.uProfileImg = sysUserInfo.uProfileImg; data.success = await _sysUserInfoServices.Update(sysUserInfo); if (data.success) { data.msg = "编辑成功"; data.response = ""; } return(data); }
// GET: sysUserInfoes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } sysUserInfo sysUserInfo = db.sysUserInfo.Find(id); if (sysUserInfo == null) { return(HttpNotFound()); } ViewBag.uCompanyID = new SelectList(db.sysOrganStruct, "osID", "osName", sysUserInfo.uCompanyID); ViewBag.uDepID = new SelectList(db.sysOrganStruct, "osID", "osName", sysUserInfo.uDepID); ViewBag.uWorkGroupID = new SelectList(db.sysOrganStruct, "osID", "osName", sysUserInfo.uWorkGroupID); return(View(sysUserInfo)); }
public async Task <MessageModel <string> > Post([FromBody] sysUserInfo sysUserInfo) { var data = new MessageModel <string>(); sysUserInfo.uLoginPWD = MD5Helper.MD5Encrypt32(sysUserInfo.uLoginPWD); sysUserInfo.uRemark = _user.Name; var id = await _sysUserInfoServices.Add(sysUserInfo); data.success = id > 0; if (data.success) { data.response = id.ObjToString(); data.msg = "添加成功"; } return(data); }
public string generatorToken(sysUserInfo sysUserInfo, string role) { //if base on user anthorization policy,then add user.if base on role anthoriaztion then add role var claims = new List <Claim> { new Claim(ClaimTypes.Name, sysUserInfo.LoginName), new Claim(JwtRegisteredClaimNames.Jti, sysUserInfo.ID.ToString()), new Claim(JwtRegisteredClaimNames.Exp, DateTime.Now.AddSeconds(_requirement.Expiration.TotalSeconds).ToString()) }; claims.Add(new Claim(ClaimTypes.Role, role)); //generator a identity var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme); identity.AddClaims(claims); var token = JwtToken.BuildJwtToken(claims.ToArray(), _requirement); return(token); }
public static sysUserInfoView EntityMap(this sysUserInfo model) { //2.0 将一个实体转换成另外一个实体 return(Mapper.Map <sysUserInfo, sysUserInfoView>(model)); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpContext context = HttpContext.Current; //从缓存中获取autofac的容器对象 var cont = CacheMgr.GetData <IContainer>(Keys.AutofacContainer); //获取到依赖注入数据 ICacheManager cacheManager = cont.Resolve <ICacheManager>(); if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckLogin), false)) { return; } if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckLogin), false)) { return; } //判断session是否为null if (filterContext.HttpContext.Request.Cookies[Keys.uinfo] == null) { if (filterContext.HttpContext.Request.Cookies[Keys.IsMember] != null) { //取出cookie中存入的uid的值 string uid = filterContext.HttpContext.Request.Cookies[Keys.IsMember].Value; //获取到依赖注入数据 IsysUserInfoServices userSer = cont.Resolve <IsysUserInfoServices>(); int iuserid = int.Parse(uid); var userinfo = userSer.QueryWhere(c => c.uID == iuserid).FirstOrDefault(); if (userinfo != null) { //将userinfo存入session //filterContext.HttpContext.Session[Keys.uinfo] = userinfo; //改用redis存储用户信息 //改用redis缓存 string sessionId = Guid.NewGuid().ToString("N");//必须保证Memcache的key唯一 cacheManager.Set(sessionId, userinfo, TimeSpan.FromHours(1)); //filterContext.HttpContext.Request.Cookies[Keys.uinfo].Value = sessionId; context.Response.Cookies[Keys.uinfo].Value = sessionId;//将自创的用户信息以Cookie的形式返回给浏览器。 BaseController.LoginUser = userinfo; } else { ToLogin(filterContext); } } else { ToLogin(filterContext); } } else { string sessionId = filterContext.HttpContext.Request.Cookies[Keys.uinfo].Value; sysUserInfo obj = cacheManager.Get <sysUserInfo>(sessionId);//获取Memcache中的数据. if (obj != null) { BaseController.LoginUser = obj; //模拟滑动过期时间。 cacheManager.Set(sessionId, obj, TimeSpan.FromHours(1)); } else { ToLogin(filterContext); } } }
static void Main(string[] args) { MyContext context = new MyContext(); sysUserInfo sysUser = context.sysUserInfos.FirstOrDefault(); }
public static sysUserInfoView EntityMap(this sysUserInfo model) { return(Mapper.Map <sysUserInfo, sysUserInfoView>(model)); }