//添加动作 public async Task <IActionResult> AdminUsersCreates(AdminUserSexes AdminUserSex, AdminUserRoleType RoleType, string AdminUserName, string AdminUserNumber, string AdminUserPhoneNumber, string AdminUserPwd) { var Aid = HttpContext.Session.GetString("Aid"); if (Aid == null) { return(RedirectToAction("Login", "Login")); } if (RoleType.ToString() == "" || AdminUserName == "" || AdminUserNumber == "" || AdminUserPwd == "") { return(Content("400")); } if (_context.AdminUser.Where(a => a.AdminUserNumber == AdminUserNumber).Count() == 0 || _context.AdminUser.Where(a => a.AdminUserName == AdminUserName).Count() == 0 || _context.AdminUser.Where(a => a.AdminUserPhoneNumber == AdminUserPhoneNumber).Count() == 0) { string AdminUserMD5Pwd = ""; MD5 md5 = MD5.Create(); byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(AdminUserPwd)); for (int i = 0; i < s.Length; i++) { AdminUserMD5Pwd = AdminUserMD5Pwd + s[i].ToString("X"); } try { var AdminUser = new AdminUser { AdminUserCode = AdminUserNumber + (int)RoleType, AdminUserName = AdminUserName, AdminUserNumber = AdminUserNumber, AdminUserPwd = AdminUserMD5Pwd, RoleType = RoleType, AdminUserSex = AdminUserSex, AdminUserPhoneNumber = AdminUserPhoneNumber }; _context.Add(AdminUser); await _context.SaveChangesAsync(); return(Content("200")); } catch (DbUpdateConcurrencyException) { return(Content("500")); } } else { return(Content("201")); } }
//修改 public IActionResult CheckAdminUsers(AdminUserSexes AdminUserSex, AdminUserRoleType RoleType, string AdminUserName, string AdminUserNumber, string AdminUserPhoneNumber, string AdminUserPwd, string Code) { var Aid = HttpContext.Session.GetString("Aid"); if (Aid == null) { return(RedirectToAction("Login", "Login")); } if (RoleType.ToString() == null || AdminUserName == null || AdminUserNumber == null || AdminUserPwd == null) { return(Content("404")); } if (_context.AdminUser.Where(a => a.AdminUserNumber == AdminUserNumber).Count() == 0 || _context.AdminUser.Where(a => a.AdminUserName == AdminUserName).Count() == 0 || _context.AdminUser.Where(a => a.AdminUserPhoneNumber == AdminUserPhoneNumber).Count() == 0) { try { var UpdateAdminUsers = _context.AdminUser.Where(a => a.AdminUserCode == Code).FirstOrDefault(); UpdateAdminUsers.AdminUserSex = AdminUserSex; UpdateAdminUsers.RoleType = RoleType; UpdateAdminUsers.AdminUserName = AdminUserName; UpdateAdminUsers.AdminUserNumber = AdminUserNumber; UpdateAdminUsers.AdminUserPhoneNumber = AdminUserPhoneNumber; UpdateAdminUsers.AdminUserPwd = AdminUserPwd; _context.SaveChanges(); return(Content("200")); } catch (DbUpdateConcurrencyException) { return(Content("500")); } } else { return(Content("301")); } }