Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        //重载了上面的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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 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());
     }
 }
Ejemplo n.º 7
0
 public void MarkDeleted(long roleId)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Role> bs = new BaseService <Role>(ctx);
         bs.MarkDeleted(roleId);
     }
 }
Ejemplo n.º 8
0
 public TravelsDTO[] GetAll()
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Travels> bs = new BaseService <Travels>(ctx);
         return(bs.GetAll().ToList().Select(p => ToDTO(p)).ToArray());
     }
 }
Ejemplo n.º 9
0
 public void MarkDeleted(long adminUserId)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <AdminUser> bs = new BaseService <AdminUser>(ctx);
         bs.MarkDeleted(adminUserId);
     }
 }
Ejemplo n.º 10
0
 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());
     }
 }
Ejemplo n.º 11
0
 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());
     }
 }
Ejemplo n.º 12
0
 public PermissionDTO[] GetAll()
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Permission> bs = new BaseService <Permission>(ctx);
         return(bs.GetAll().ToList().Select(c => ToDTO(c)).ToArray());
     }
 }
Ejemplo n.º 13
0
 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());
     }
 }
Ejemplo n.º 14
0
 public void RecoveryDeleted(long id)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Guide> bs = new BaseService <Guide>(ctx);
         bs.RecoveryDeleted(id);
     }
 }
Ejemplo n.º 15
0
 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());
     }
 }
Ejemplo n.º 16
0
 public void MarkDeleted(long cid)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Guide> bs = new BaseService <Guide>(ctx);
         bs.MarkDeleted(cid);
     }
 }
Ejemplo n.º 17
0
 public UserDTO[] GetRecoveries()
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <User> bs = new BaseService <User>(ctx);
         return(bs.GetRecoveries().ToList().Select(e => ToDTO(e)).ToArray());
     }
 }
Ejemplo n.º 18
0
 public void MarkDeleted(long id)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <User> bs = new BaseService <User>(ctx);
         bs.MarkDeleted(id);
     }
 }
Ejemplo n.º 19
0
 public GuideDTO[] GetAll()
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Guide> bs = new BaseService <Guide>(ctx);
         return(bs.GetAll().ToList().Select(e => ToDTO(e)).ToArray());
     }
 }
Ejemplo n.º 20
0
 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());
     }
 }
Ejemplo n.º 21
0
 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();
     }
 }
Ejemplo n.º 22
0
        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());
            }
        }
Ejemplo n.º 23
0
 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));
     }
 }
Ejemplo n.º 24
0
 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);
     }
 }
Ejemplo n.º 25
0
 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));
     }
 }
Ejemplo n.º 26
0
 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));
     }
 }
Ejemplo n.º 27
0
 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));
     }
 }
Ejemplo n.º 28
0
 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));
     }
 }
Ejemplo n.º 29
0
 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));
     }
 }
Ejemplo n.º 30
0
 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));
     }
 }