public dynamic DeleteUser(sys_user user) { if (userFactoty.CreatUserService().DeleteUser(user)) { return "OK"; } return "FAIL"; }
public dynamic AddUser(sys_user user) { if ( userFactoty.CreatUserService().AddUser(user)) { return "OK"; } return "FAIL"; //return new RedirectResult("/user/index"); //return "<script>alert('123')</script>"; ; }
/// <summary> /// 删除数据 /// </summary> /// <param name="entity">实体类</param> /// <returns></returns> public bool Delete(sys_user entity) { return(_Sys_UserRepositoryS.Delete(entity)); }
public ActionResult Register(FormCollection collection) { string loginid = Request["name"].Trim(); if (string.IsNullOrEmpty(loginid)) { return(Content(ReturnMsg(Enum_Return.失败, "登录账号不能为空!", null))); } string email = Request["email"].Trim(); if (string.IsNullOrEmpty(email)) { return(Content(ReturnMsg(Enum_Return.失败, "邮箱地址不能为空!", null))); } string pwd = Request["pwd"].Trim(); if (string.IsNullOrEmpty(pwd)) { return(Content(ReturnMsg(Enum_Return.失败, "登录密码不能为空!", null))); } if (pwd.Length < 6) { return(Content(ReturnMsg(Enum_Return.失败, "登录密码不能小于6个字符!", null))); } string repwd = Request["repwd"].Trim(); if (pwd != repwd) { return(Content(ReturnMsg(Enum_Return.失败, "确认密码与密码不一致!", null))); } var isloginid = db.sys_user.Where(c => c.user_name == loginid).FirstOrDefault(); if (isloginid != null) { return(Content(ReturnMsg(Enum_Return.失败, "登录账号已存在!", null))); } var isemail = db.sys_user.Where(c => c.user_email == email).FirstOrDefault(); if (isemail != null) { return(Content(ReturnMsg(Enum_Return.失败, "邮箱地址已存在!", null))); } sys_user model = new sys_user(); model.user_name = loginid; model.user_nickname = loginid; model.user_email = email; model.user_password = pwd; model.user_role = (int)Enum_User.管理员; model.apply_status = (int)Enum_Member_Status.正常; model.create_time = DateTime.Now; model.update_time = DateTime.Now; model.user_face = "/Content/img/default_headpic.png"; db.sys_user.Add(model); db.Configuration.ValidateOnSaveEnabled = false; int n = db.SaveChanges(); db.Configuration.ValidateOnSaveEnabled = true; if (n <= 0) { return(Content(ReturnMsg(Enum_Return.失败, "注册失败!", null))); } return(Content(ReturnMsg(Enum_Return.成功, "注册成功,等待管理员审核!", null))); }
public dynamic PostFile() { // 设置上传目录 // var provider = new MultipartFormDataStreamProvider(@"D:\"); // 接收数据,并保存文件 // Request.Content.ReadAsMultipartAsync(provider); try { var context = HttpContext.Current; var request = context.Request; //保存文件 var postFile = request.Files[0]; string uploadPath = HttpContext.Current.Server.MapPath("~/Upload/"); if (!Directory.Exists(uploadPath)) Directory.CreateDirectory(uploadPath); string filePath = postFile.FileName.Substring(postFile.FileName.LastIndexOf("\\") + 1); string fileType = filePath.Substring(filePath.LastIndexOf(".")); filePath = filePath.Substring(0, filePath.LastIndexOf(".")); filePath = uploadPath + filePath + DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond + fileType; request.Files[0].SaveAs(filePath); //读取文件 var dt = new DataTable(); var msg = ReadFile(filePath,ref dt); if (!string.IsNullOrEmpty(msg)) { throw new Exception(msg); } using (var db = Db.Context("Mms")) { db.UseTransaction(true); try { foreach (DataRow row in dt.Rows) { var user = new sys_user(); user.UserCode = row[0].ToString(); user.UserName = row[1].ToString(); user.Description = row[2].ToString(); user.IsEnable = row[3].ToString().ToLower() == "true"; int count; if (!int.TryParse(row[4].ToString(), out count)) { count = 0; } DateTime date; if (!DateTime.TryParse(row[5].ToString(), out date)) { date = DateTime.Now; } user.LoginCount = count; user.LastLoginDate = date; var ret = db.Sql("select 1 from test_user where UserCode =@0", user.UserCode).QuerySingle<int>(); if (ret <= 0) { db.Insert<sys_user>("test_user", user).AutoMap().Execute(); } else { db.Update<sys_user>("test_user", user).AutoMap(x => x.UserCode).Where(x => x.UserCode).Execute(); } } db.Commit(); } catch (Exception ex) { db.Rollback(); throw ex; } } } catch(Exception e) { return new { error = e.Message, preventRetry = true }; } //返回前台 return new { success = true, message = "导入成功!" }; }
/// <summary> /// 登陆 /// </summary> /// <param name="user"></param> /// <returns></returns> public dynamic LoginIn(sys_user user) { var sql = String.Format(@"select * from sys_user where UserName=@0 and Password=@1 and IsEnable=1 "); return db.Query<sys_user>(sql,user.UserName, user.Password).ToList(); }
public ActionResult UpdateProfile(sys_user dto) { dto.pass_word = Encrypt.DesEncrypt(dto.pass_word.Trim()); _userApp.UpdateProfile(dto); return(Success("修改成功")); }
public APIRst AddUser(sys_user user) { user.Uid = 0; return(infoHelper.SetUser(user)); }
public ActionResult Add(FormCollection formcollection) { string usertype = formcollection["role_id"]; string userid = formcollection["username"]; string password = formcollection["password"]; string name = formcollection["name"]; string department = formcollection["dept_id"]; string position = formcollection["position"]; string qualification = formcollection["qualification"]; string idnum = formcollection["id_number"]; string phone = formcollection["phone_number"]; System.DateTime time = new DateTime(); time = DateTime.Now; System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider(); byte[] saltBytes = new byte[36]; rng.GetBytes(saltBytes); string salt = Convert.ToBase64String(saltBytes); //string salt = ToHexString(saltBytes); //ViewBag.salt = salt; /*属性剩余id photo salt三个属性,id自增 salt随机生成 photo路径*/ if (usertype != "" && userid != "" && password != "" && name != "" && department != "" && position != "" && qualification != "" && idnum != "" && phone != "") { ViewBag.SubmitForm = usertype + " " + userid + " " + password + " " + name + " " + department + " " + position + " " + qualification + " " + idnum + " " + phone + " " + time; gensysEntities gensysdb = new gensysEntities(); var distinctUser = (from d in gensysdb.sys_user where d.username == userid select d); if (distinctUser.Count() == 0) { sys_user useradd = new sys_user(); useradd.role_id = usertype; useradd.username = userid; useradd.password = password; useradd.salt = salt; useradd.name = name; useradd.dept_id = department; useradd.position = position; useradd.qualification = qualification; useradd.id_number = idnum; useradd.phone_number = phone; useradd.register_date = time; gensysdb.sys_user.Add(useradd); gensysdb.SaveChanges(); } else { var script = String.Format("<script>alert('用户名重复!');location.href='{0}'</script>", Url.Action("Index", "UserMana")); //Url.Action()用于指定跳转的路径 return(Content(script, "text/html")); } } else { ViewBag.SubmitForm = "输入数据有误"; var script = String.Format("<script>alert('输入数据有误!');location.href='{0}'</script>", Url.Action("Index", "UserMana")); //Url.Action()用于指定跳转的路径 return(Content(script, "text/html")); } //List<sys_user> list = gensysdb.sys_user.ToList(); //return Json(newproduct.ToList(), JsonRequestBehavior.AllowGet); return(RedirectToAction("Index")); }
public int Insert(sys_user user) { return(conn.Execute("INSERT INTO sys_user values (@id, @Name, @Password, @Level, @Remark)", user)); }
/// <summary> /// 设置用户信息 /// </summary> /// <param name="user">用户信息</param> /// <returns></returns> public int SetUser(sys_user user) { return(dal.SetUser(user)); }
public void UpdateLog <T>(T entity, T orginalobj) { if (!islog) { return; } object id = 0; StringBuilder txt = new StringBuilder(); sys_log slog = EntityFields <T>(entity); slog.fields.TryGetValue("id", out id); sys_user user = CacheManager.Instance().Current_User; txt.Append($"[{user.name}]更新{slog.tablename},"); var cnames = slog.fields.Select(t => t.Key); Type orgtype = orginalobj.GetType(); PropertyInfo[] orgproinfos = orgtype.GetProperties().Where(t => cnames.Contains(t.Name)).ToArray(); foreach (var item in orgproinfos) { string fn = string.Empty; object fv = null; object fvnew = null; var orgattrs = item.GetCustomAttributes(typeof(DbFieldAttribute)); if (orgattrs.Count() > 0) { DbFieldAttribute attr = orgattrs.First() as DbFieldAttribute; fn = attr.FieldName; fv = item.GetValue(orginalobj); string coltype = item.PropertyType.Name; slog.fields.TryGetValue(fn, out fvnew); switch (coltype) { case "Int32": if (Convert.ToInt32(fv) != Convert.ToInt32(fvnew ?? 0)) { txt.Append($"[{attr.Label}]:{fv}->{fvnew},"); } break; case "String": if (fv.ToString() != (fvnew ?? "").ToString()) { txt.Append($"[{attr.Label}]:{fv}->{fvnew},"); } break; case "DateTime": if (Convert.ToDateTime(fv) != Convert.ToDateTime(fvnew)) { txt.Append($"[{attr.Label}]:{fv}->{fvnew},"); } break; case "Double": if (Convert.ToDouble(fv) != Convert.ToDouble(fvnew ?? 0)) { txt.Append($"[{attr.Label}]:{fv}->{fvnew},"); } break; case "Float": if (Convert.ToSingle(fv) != Convert.ToSingle(fvnew ?? 0)) { txt.Append($"[{attr.Label}]:{fv}->{fvnew},"); } break; case "Decimal": if (Convert.ToDecimal(fv) != Convert.ToDecimal(fvnew ?? 0)) { txt.Append($"[{attr.Label}]:{fv}->{fvnew},"); } break; default: break; } } } log.Info(txt.ToString()); }
public JsonResult SaveData(sys_user dto) { _userApp.SaveData(dto); return(JsonJui()); }
/// <summary> /// 修改用户 /// </summary> /// <param name="sys_user"></param> public int EditUser(sys_user sys_user) { return(dal.EditUser(sys_user)); }
public async Task <IActionResult> Edit(int id, UserRoleViewModel user_roles) { if (id != user_roles.User.id) { return(NotFound()); } if (user_roles.Roles == null) { return(NotFound()); } if (user_roles.User.password == null) { var user = new sys_user() { id = user_roles.User.id, usercode = user_roles.User.usercode, password = user_roles.User.password }; _context.Attach(user); _context.Entry(user).CurrentValues.SetValues(user_roles.User); } else { var user = new sys_user() { id = user_roles.User.id, usercode = user_roles.User.usercode }; var password_hash = PasswordHash(user_roles.User.password); user_roles.User.password = password_hash; _context.Attach(user); _context.Entry(user).CurrentValues.SetValues(user_roles.User); //_context.Update(user_roles.User); } var web_user_role = _context.sys_user_role.Where(x => x.sys_user_id == id); _context.sys_user_role.RemoveRange(web_user_role); List <sys_user_role> user_role_list = new List <sys_user_role>(); var roles = user_roles.Roles; if (roles.Count() > 0) { foreach (var item in roles) { if (item.Selected == true) { user_role_list.Add( new sys_user_role() { sys_user_id = id, sys_role_id = item.role_id } ); } } } _context.AddRange(user_role_list); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!sys_userExists(user_roles.User.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); }
public int Update(sys_user t) { return(conn.Execute("UPDATE sys_user SET Name=@Name, Password=@Password,Remark=@Remark WHERE id=@id", t)); }
// POST: api/Member public IHttpActionResult Post([FromBody] sys_user user) { sys_userService.Insert(user); return(Ok()); }
public async Task <IActionResult> Put(int id, [FromBody] sys_user value) { if (id == 0) { //修改密码 var usr = _sysUserRpt.GetSingle(f => f.Id == value.Id); if (usr != null) { usr.Pwd = value.Pwd; _sysUserRpt.Update(usr); _sysUserRpt.Commit(); } } else { using (var tran = _context.Database.BeginTransaction()) { try { sys_user userDb = _sysUserRpt.GetSingle(id); if (userDb == null) { return(NotFound()); } if (value.RoleIds != userDb.RoleIds) { //修改了用户角色 _sysRoleUserRpt.DeleteWhere(f => f.UserId == id); _sysRoleUserRpt.Commit(); //新增用户角色关系表 string[] roles = value.RoleIds.Split(",".ToArray()); foreach (var item in roles) { if (!string.IsNullOrEmpty(item)) { var userrole = new sys_role_user { RoleId = int.Parse(item), UserId = id }; _sysRoleUserRpt.Add(userrole); } } _sysRoleUserRpt.Commit(); } userDb.IsValid = value.IsValid; userDb.Mobile = value.Mobile; userDb.Tel = value.Tel; userDb.Works = value.Works; userDb.Title = value.Title; userDb.UserId = value.UserId; userDb.UserName = value.UserName; userDb.UpdatedAt = DateTime.Now; userDb.RoleIds = value.RoleIds; _sysUserRpt.Commit(); tran.Commit(); } catch (Exception ex) { Console.WriteLine(ex); tran.Rollback(); return(BadRequest(ex)); } } } return(new NoContentResult()); }
// PUT: api/Member/5 public IHttpActionResult Put(int id, [FromBody] sys_user user) { sys_userService.Update(user); return(Ok()); }
public APIRst SetUser(sys_user user) { return(infoHelper.SetUser(user)); }
/// <summary> /// 写入实体数据 /// </summary> /// <param name="entity">实体类</param> /// <returns></returns> public long Insert(sys_user entity) { return(_Sys_UserRepositoryS.Insert(entity)); }
/// <summary> /// 删除用户 /// </summary> /// <param name="user"></param> /// <returns></returns> public dynamic DeleteUser(sys_user user) { try { user.IsEnable = false; db.BeginTransaction(); // var sql = String.Format(@"insert sys_role(RoleName,Description) values (@0,@1) "); // int result = (int)db.Insert("sys_role", "role.RoleName,", role.RoleName, role.Description); var sql = String.Format(@"update sys_user set IsEnable=0 where UserID=@0 "); var result = db.Execute(sql, user.UserID); db.CompleteTransaction(); return true; } catch (Exception) { return false; } return false; }
/// <summary> /// 更新实体数据 /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool Update(sys_user entity) { return(_Sys_UserRepositoryS.Update(entity)); }
/// <summary> /// 添加用户 /// </summary> /// <param name="user"></param> /// <returns></returns> public dynamic AddUser(sys_user user) { try { user.IsEnable = true; db.BeginTransaction(); // var sql = String.Format(@"insert sys_role(RoleName,Description) values (@0,@1) "); // int result = (int)db.Insert("sys_role", "role.RoleName,", role.RoleName, role.Description); var result = (int)db.Insert(user); db.CompleteTransaction(); return true; } catch (Exception) { return false; } return false; }
/// <summary> /// 更新实体数据 /// </summary> /// <param name="entity"></param> /// <param name="updateColumns">修改字段表达式树</param> /// <returns></returns> public bool Update(sys_user entity, Expression <Func <sys_user, object> > updateColumns) { return(_Sys_UserRepositoryS.Update(entity, updateColumns)); }
public dynamic LoginIn(sys_user user) { IUserFactoty userFactoty=new UserFactoty(); List<sys_user> loginUser = userFactoty.CreatUserService().LoginIn(user); if (loginUser.Count>0) { Session["UserName"] = user.UserName; Session["UserID"] = loginUser[0].UserID; return "/admin/index"; } return "/admin/error"; ; }
public returnR userUpdate(JObject userObj) { returnR r = new returnR(); r.code = (int)sysEnum.还没有执行; if (userObj == null) { r.code = (int)sysEnum.参数必填; return(r); } //这里执行 try { #region 判断用户 string userId = userObj["userId"].ToString(); if (string.IsNullOrEmpty(userId)) { r.code = (int)sysEnum.参数必填; r.msg = "userId必填"; return(r); } string username = userObj["userName"].ToString(); if (string.IsNullOrEmpty(username)) { r.code = (int)sysEnum.参数必填; r.msg = "用户名称必填"; return(r); } sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); var dataList = db.Queryable <sys_user>() .Where(it => it.userName == username && it.flag == 1 && it.userId.ToString() != userId).ToList(); if (dataList.Count > 0) { r.code = (int)sysEnum.数据库中已经存在; r.msg = "数据库中已存在[" + username + "]"; return(r); } #endregion sysLoginInCls si = public_method.getLoginInObject(); string realName = userObj["realName"].ToString(); sys_user sys_user = new sys_user(); sys_user.userId = int.Parse(userId); sys_user.userName = username; sys_user.realName = realName; sys_user.roleId = int.Parse(userObj["roleId"].ToString()); sys_user.dataRoleId = int.Parse(userObj["dataRoleId"].ToString()); sys_user.phone = userObj["phone"].ToString(); sys_user.email = userObj["email"].ToString(); sys_user.remarks = userObj["remarks"].ToString(); sys_user.updateUserId = si.loginUserId; //更新人 sys_user.updateDate = System.DateTime.Now; //更新时间 sys_user.flag = 1; //默认开启 //这里转换一下 int iReturn = db.Updateable(sys_user) .IgnoreColumns(it => new { it.createDate, it.createUserId, it.pwd }).ExecuteCommand(); if (iReturn > 0) { r.code = (int)sysEnum.操作成功; r.msg = "更新[" + username + "]成功"; #region //写日志 sys_log sys_log = new sys_log(); sys_log.logType = "更新"; sys_log.logText = Newtonsoft.Json.JsonConvert.SerializeObject(sys_user); sys_log.createUserId = si.loginUserId; public_method.saveLog(sys_log); #endregion return(r); } else { r.code = (int)sysEnum.执行数据库失败; r.msg = "更新[" + username + "]失败"; return(r); } } catch (Exception ex) { r.code = (int)sysEnum.发生异常; r.msg = ex.Message; } return(r); }