public IHttpActionResult UserLogin(string name, string password) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password)) { return(Json(new { result = "用户名或密码错误" })); } using (ERPDBEntities db = new ERPDBEntities()) { var encode_pass = SystemCommon.GetMD5Str(password); var user = db.Staff.FirstOrDefault(a => a.name == name && a.password == encode_pass); if (user == null) { return(Json(new { result = "用户不存在" })); } return(Json(new { result = "登陆成功", data = user.id })); } }
public IHttpActionResult AddUser(string name, string password, int leader_id, string user_type, decimal salary, string sell_product_type) { try { if (string.IsNullOrEmpty(name)) { return(Json(new { result = "用户名不能为空" })); } Enum_User_Type userType; bool convertResult = Enum.TryParse(user_type, out userType); if (convertResult == false) { return(Json(new { result = "用户类型异常" })); } Staff user = new Staff(); user.name = name; user.password = string.IsNullOrEmpty(password) ? SystemCommon.GetMD5Str(SystemCommon.Default_Password) : SystemCommon.GetMD5Str(password); user.leader_id = leader_id; user.user_type = user_type; user.salary = salary; user.sell_product_type = sell_product_type; user.create_time = DateTime.Now; user.update_time = DateTime.Now; using (ERPDBEntities db = new ERPDBEntities()) { db.Entry(user).State = System.Data.Entity.EntityState.Added; if (db.SaveChanges() < 0) { return(Json(new { result = "用户添加失败" })); } } return(Json(new { result = "用户添加成功" })); } catch (Exception ex) { } return(Json(new { result = "系统异常" })); }