public bool UpdateUser(long id, string nickname, string phoneNum, string gender, string password, string email) { using (Dbcontext ctx = new Dbcontext()) { BaseService <User> bs = new BaseService <User>(ctx); var user = bs.GetById(id); if (user == null) { throw new ArgumentException("找不到id=" + id + "的用户"); } user.NickName = nickname; user.PhoneNum = phoneNum; user.Gender = gender; user.Email = email; if (!string.IsNullOrEmpty(password)) { user.PasswordHash = commonhelper.CalcMD5(user.PasswordSalt + password); } ctx.SaveChanges(); return(true); } }
public bool UpdateGuide(long id, string school, string intro) { using (Dbcontext ctx = new Dbcontext()) { try { BaseService <Guide> bs = new BaseService <Guide>(ctx); BaseService <User> userbs = new BaseService <User>(ctx); var guide = bs.GetById(id); var user = userbs.GetById(guide.Users_Id); if (guide == null) { throw new ArgumentException("找不到id=" + id + "的导游"); } if (user == null) { throw new ArgumentException("找不到id=" + guide.Users_Id + "的用户"); } guide.school = school; guide.intro = intro; ctx.SaveChanges(); return(true); } catch { return(false); } } }
public long AddUser(string account, string nickename, string phoneNum, string gender, string password, string email) { User user = new User(); user.Email = email; user.NickName = nickename; user.PhoneNum = phoneNum; user.Gender = gender; user.Account = account; var salt = commonhelper.CreateVerifyCode(4); user.PasswordSalt = salt; string pwdHash = commonhelper.CalcMD5(salt + password); user.PasswordHash = pwdHash; using (Dbcontext ctx = new Dbcontext()) { BaseService <User> bs = new BaseService <User>(ctx); bool exists = bs.GetAll().Any(e => e.PhoneNum == phoneNum); if (exists) { throw new ArgumentException("手机号已经存在" + phoneNum); } ctx.User.Add(user); ctx.SaveChanges(); } return(user.Id); }
//重载了上面的AddUser方法,传进来一个UserDTO的对象,然后对上面的方法进行少量修改 public long AddUser(UserDTO model) { User user = new User(); user.Email = model.Email; user.NickName = model.NickName; user.PhoneNum = model.PhoneNum; user.Gender = model.Gender; user.Account = model.Account; var salt = commonhelper.CreateVerifyCode(4); user.PasswordSalt = salt; string pwdHash = commonhelper.CalcMD5(salt + model.Password); user.PasswordHash = pwdHash; var level = checkpassword(model.Password); user.level = level; using (Dbcontext ctx = new Dbcontext()) { BaseService <User> bs = new BaseService <User>(ctx); bool exists = bs.GetAll().Any(e => e.Account == model.Account); if (exists) { return(-123); //这里要注意以下,上面的原方法中是抛出一个异常,但是如果是发布之后的话,异常是要进行处理掉的,不然会出现黄屏等问题 //我这里就暂时定义了 -123的意思就是存在相同的账号,这个是可以随意修改,但是最好有一定规则 } ctx.User.Add(user); ctx.SaveChanges(); } return(user.Id); }
private GuideDTO ToDTO(Guide r) { GuideDTO dto = new GuideDTO(); dto.CreateDateTime = r.CreateDateTime; dto.Id = r.Id; dto.intro = r.intro; dto.isappointment = r.isappointment; dto.level = r.level; dto.shenhe = r.shenhe; dto.picture = r.picture; dto.school = r.school; dto.schoolnum = r.schoolnum; dto.jifen = r.jifen; dto.school = r.school; using (Dbcontext ctx = new Dbcontext()) { BaseService <User> bs = new BaseService <User>(ctx); var user = bs.GetById(r.Users_Id); if (user != null) { dto.nickname = user.NickName; } } dto.Users_Id = r.Users_Id; //using (Dbcontext ctx = new Dbcontext()) //{ // BaseService<User> bs = new BaseService<User>(ctx); // var Guide_UserInfo = bs.GetAll().Where(e => e.Id == r.Users_Id).FirstOrDefault(); // // dto.NickName = Guide_UserInfo.NickName; //} return(dto); }
public long GetGid(long uid) { using (Dbcontext ctx = new Dbcontext()) { BaseService <GuideUser> bs = new BaseService <GuideUser>(ctx); return(bs.GetAll().Where(e => e.Uid == uid).Select(p => p.GuideId).SingleOrDefault()); } }
public void MarkDeleted(long roleId) { using (Dbcontext ctx = new Dbcontext()) { BaseService <Role> bs = new BaseService <Role>(ctx); bs.MarkDeleted(roleId); } }
public TravelsDTO[] GetAll() { using (Dbcontext ctx = new Dbcontext()) { BaseService <Travels> bs = new BaseService <Travels>(ctx); return(bs.GetAll().ToList().Select(p => ToDTO(p)).ToArray()); } }
public void MarkDeleted(long adminUserId) { using (Dbcontext ctx = new Dbcontext()) { BaseService <AdminUser> bs = new BaseService <AdminUser>(ctx); bs.MarkDeleted(adminUserId); } }
public LineDTO[] GetByFour() { using (Dbcontext ctx = new Dbcontext()) { BaseService <Line> bs = new BaseService <Line>(ctx); return(bs.GetAll().OrderByDescending(p => p.NumOfPeople).Take(4).ToList().Select(p => ToDTO(p)).ToArray()); } }
public PermissionDTO[] GetByRoleId(long roleId) { using (Dbcontext ctx = new Dbcontext()) { BaseService <Role> bs = new BaseService <Role>(ctx); return(bs.GetById(roleId).Permissions.Select(e => ToDTO(e)).ToArray()); } }
public PermissionDTO[] GetAll() { using (Dbcontext ctx = new Dbcontext()) { BaseService <Permission> bs = new BaseService <Permission>(ctx); return(bs.GetAll().ToList().Select(c => ToDTO(c)).ToArray()); } }
public long[] GetRoleId(long adminuserid) { using (Dbcontext ctx = new Dbcontext()) { BaseService <AdminUserRoles> bs = new BaseService <AdminUserRoles>(ctx); return(bs.GetAll().Where(e => e.AdminUserId == adminuserid).Select(e => e.RoleId).ToArray()); } }
public void RecoveryDeleted(long id) { using (Dbcontext ctx = new Dbcontext()) { BaseService <Guide> bs = new BaseService <Guide>(ctx); bs.RecoveryDeleted(id); } }
public long[] GetLid(long gid) { using (Dbcontext ctx = new Dbcontext()) { BaseService <GuidLines> bs = new BaseService <GuidLines>(ctx); return(bs.GetAll().Where(e => e.Gid == gid).Select(p => p.Lid).ToArray()); } }
public void MarkDeleted(long cid) { using (Dbcontext ctx = new Dbcontext()) { BaseService <Guide> bs = new BaseService <Guide>(ctx); bs.MarkDeleted(cid); } }
public UserDTO[] GetRecoveries() { using (Dbcontext ctx = new Dbcontext()) { BaseService <User> bs = new BaseService <User>(ctx); return(bs.GetRecoveries().ToList().Select(e => ToDTO(e)).ToArray()); } }
public void MarkDeleted(long id) { using (Dbcontext ctx = new Dbcontext()) { BaseService <User> bs = new BaseService <User>(ctx); bs.MarkDeleted(id); } }
public GuideDTO[] GetAll() { using (Dbcontext ctx = new Dbcontext()) { BaseService <Guide> bs = new BaseService <Guide>(ctx); return(bs.GetAll().ToList().Select(e => ToDTO(e)).ToArray()); } }
public long GetGid(long Lid) { using (Dbcontext ctx = new Dbcontext()) { BaseService <GuidLines> bs = new BaseService <GuidLines>(ctx); return(bs.GetAll().Where(e => e.Lid == Lid).Select(p => p.Gid).SingleOrDefault()); } }
public void changlevel(long level, long gid) { using (Dbcontext ctx = new Dbcontext()) { BaseService <Guide> bs = new BaseService <Guide>(ctx); bs.GetById(gid).level = (int)level; ctx.SaveChanges(); } }
public TravelsDTO[] GetByShenhe() { using (Dbcontext ctx = new Dbcontext()) { BaseService <Travels> bs = new BaseService <Travels>(ctx); return(bs.GetAll().Where(e => e.shenhe == false).ToList().Select(e => ToDTO(e)).ToArray()); } }
public GuideDTO GetByUid(long uid) { using (Dbcontext ctx = new Dbcontext()) { BaseService <Guide> bs = new BaseService <Guide>(ctx); var guide = bs.GetAll().SingleOrDefault(e => e.Users_Id == uid); return(ToDTO(guide)); } }
public long[] GetLids(long id) { using (Dbcontext ctx = new Dbcontext()) { BaseService <GuidLines> bs = new BaseService <GuidLines>(ctx); var lines = bs.GetAll().Where(e => e.Gid == id).ToList().Select(e => e.Lid).ToArray(); return(lines); } }
public TravelsDTO GetByLid(long id) { using (Dbcontext ctx = new Dbcontext()) { BaseService <Travels> bs = new BaseService <Travels>(ctx); var line = bs.GetAll().SingleOrDefault(e => e.Id == id); return(ToDTO(line)); } }
public UserDTO GetById(long id) { using (Dbcontext ctx = new Dbcontext()) { BaseService <User> bs = new BaseService <User>(ctx); var user = bs.GetById(id); return(user == null ? null : ToDTO(user)); } }
public UserDTO GetByAccount(string account) { using (Dbcontext ctx = new Dbcontext()) { BaseService <User> bs = new BaseService <User>(ctx); var user = bs.GetAll().SingleOrDefault(e => e.Account == account); return(user == null ? null : ToDTO(user)); } }
public PermissionDTO GetById(long id) { using (Dbcontext ctx = new Dbcontext()) { BaseService <Permission> bs = new BaseService <Permission>(ctx); var pe = bs.GetById(id); return(pe == null ? null : ToDTO(pe)); } }
public UserDTO GetByPhoneNum(string phoneNum) { using (Dbcontext ctx = new Dbcontext()) { BaseService <User> bs = new BaseService <User>(ctx); var user = bs.GetAll().SingleOrDefault(e => e.PhoneNum == phoneNum); return(user == null ? null : ToDTO(user)); } }
public RoleDTO GetById(long Id) { using (Dbcontext ctx = new Dbcontext()) { BaseService <Role> bs = new BaseService <Role>(ctx); var role = bs.GetById(Id); return(role == null ? null : ToDTO(role)); } }