Exemple #1
0
        public void MarkDeleted(long id)
        {
            var data = GetById(id);

            data.IsDeleted = true;
            ctx.SaveChanges();
        }
Exemple #2
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);
        }
Exemple #3
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);
     }
 }
Exemple #4
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);
        }
Exemple #5
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);
                }
            }
        }
Exemple #6
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();
     }
 }
Exemple #7
0
 public void Shenhe(long id)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Guide> bs = new BaseService <Guide>(ctx);
         var data = bs.GetById(id);
         data.shenhe = true;
         ctx.SaveChanges();
     }
 }
Exemple #8
0
 public void RecoveryDeleted(long id)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <GuideUser> bs = new BaseService <GuideUser>(ctx);
         GuideUser gu = bs.GetRecoveries().Where(e => e.GuideId == id).SingleOrDefault();
         gu.IsDeleted = false;
         ctx.SaveChanges();
     }
 }
Exemple #9
0
 public bool ClickTops(long Uid, long Tid)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         UserTravels ut = new UserTravels();
         ut.UId = Uid;
         ut.TId = Tid;
         ctx.UserTravels.Add(ut);
         ctx.SaveChanges();
         return(true);
     }
 }
Exemple #10
0
        public long AddGuideUser(long uid, long gid)
        {
            GuideUser g = new GuideUser();

            g.Uid     = uid;
            g.GuideId = gid;
            using (Dbcontext ctx = new Dbcontext())
            {
                ctx.GuideUser.Add(g);
                ctx.SaveChanges();
            }

            return(g.Id);
        }
Exemple #11
0
 public void UpdatePermission(long id, string permName, string description)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Permission> bs = new BaseService <Permission>(ctx);
         var perm = bs.GetById(id);
         if (perm == null)
         {
             throw new ArgumentException("id不存在" + id);
         }
         perm.Name        = permName;
         perm.Description = description;
         ctx.SaveChanges();
     }
 }
Exemple #12
0
 public bool CompleteOrder(long oid)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Order> bs = new BaseService <Order>(ctx);
         var order = bs.GetById(oid);
         if (order == null)
         {
             return(false);
         }
         order.state = 1;
         ctx.SaveChanges();
         return(true);
     }
 }
Exemple #13
0
        public long AddGidLid(long gid, long lid)
        {
            GuidLines GLs = new GuidLines();

            GLs.Gid = gid;
            GLs.Lid = lid;

            using (Dbcontext ctx = new Dbcontext())
            {
                ctx.GuidLines.Add(GLs);
                ctx.SaveChanges();
            }

            return(GLs.Id);
        }
Exemple #14
0
        public long AddTravel(string title, string context, long?tops, long Uid)
        {
            Travels lines = new Travels();

            lines.title   = title;
            lines.content = context;
            lines.tops    = tops;
            lines.Uid     = Uid;

            using (Dbcontext ctx = new Dbcontext())
            {
                ctx.Travels.Add(lines);
                ctx.SaveChanges();
            }
            return(lines.Id);
        }
Exemple #15
0
 public void Update(long roleId, string roleName)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Role> roleBS = new BaseService <Role>(ctx);
         bool exists = roleBS.GetAll().Any(r => r.Name == roleName && r.Id != roleId);
         if (exists)
         {
             throw new ArgumentException("角色名字已存在" + roleName);
         }
         Role role = new Role();
         role.Id = roleId;
         ctx.Entry(role).State = System.Data.Entity.EntityState.Unchanged;
         role.Name             = roleName;
         ctx.SaveChanges();
     }
 }
Exemple #16
0
 public long AddNew(string roleName)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Role> bs = new BaseService <Role>(ctx);
         bool exists           = bs.GetAll().Any(e => e.Name == roleName);
         if (exists)
         {
             throw new ArgumentException("角色名字已经存在" + roleName);
         }
         Role role = new Role();
         role.Name = roleName;
         ctx.Role.Add(role);
         ctx.SaveChanges();
         return(role.Id);
     }
 }
Exemple #17
0
 public long AddPermission(string permName, string description)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Permission> permBS = new BaseService <Permission>(ctx);
         bool exists = permBS.GetAll().Any(p => p.Name == permName);
         if (exists)
         {
             throw new ArgumentException("权限项已经存在");
         }
         Permission perm = new Permission();
         perm.Name        = permName;
         perm.Description = description;
         ctx.Permission.Add(perm);
         ctx.SaveChanges();
         return(perm.Id);
     }
 }
Exemple #18
0
        public long?Updatetops(long id)
        {
            using (Dbcontext ctx = new Dbcontext())
            {
                try
                {
                    BaseService <Travels> bs = new BaseService <Travels>(ctx);
                    bs.GetById(id).tops += 1;
                    ctx.SaveChanges();
                    return(bs.GetById(id).tops);
                }

                catch (DbEntityValidationException ex)
                {
                    return(null);
                }
            }
        }
Exemple #19
0
 public bool AddNumOfPeople(long tid)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         try
         {
             BaseService <Line> bs = new BaseService <Line>(ctx);
             var line = bs.GetById(tid);
             line.NumOfPeople += 1;
             ctx.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Exemple #20
0
 public bool AddSchool(string name)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         try
         {
             school s = new school();
             s.schoolname = name;
             ctx.school.Add(s);
             ctx.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Exemple #21
0
 public bool Addjifen(long gid)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         try
         {
             BaseService <Guide> bs = new BaseService <Guide>(ctx);
             var guide = bs.GetById(gid);
             guide.jifen += 10;
             ctx.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Exemple #22
0
        public long AddLine(string Province, string city, string intro, string title, long PastPrice, float discount)
        {
            Line lines = new Line();

            lines.Province  = Province;
            lines.city      = city;
            lines.intro     = intro;
            lines.title     = title;
            lines.NowPrice  = (PastPrice * (discount * 0.1));
            lines.PastPrice = PastPrice;
            lines.discount  = discount;

            using (Dbcontext ctx = new Dbcontext())
            {
                ctx.Line.Add(lines);
                ctx.SaveChanges();
            }
            return(lines.Id);
        }
Exemple #23
0
 public bool appointment(long GuideId, long Uid)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         try
         {
             GuideUser u = new GuideUser();
             u.GuideId = GuideId;
             u.Uid     = Uid;
             ctx.GuideUser.Add(u);
             ctx.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }
Exemple #24
0
 public void UpdateTravel(long id, string title, string context, long tops, long Uid)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Travels> bs
             = new BaseService <Travels>(ctx);
         var line = bs.GetById(id);
         if (line == null)
         {
             throw new ArgumentException("找不到id=" + id + "的游记");
         }
         line.title   = title;
         line.content = context;
         line.tops    = tops;
         line.title   = title;
         line.Uid     = Uid;
         ctx.SaveChanges();
     }
 }
Exemple #25
0
 public bool appointment(long uid, long oid)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         try
         {
             OrderUser ou = new OrderUser();
             ou.Uid = uid;
             ou.Oid = oid;
             ctx.OrderUser.Add(ou);
             ctx.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Exemple #26
0
        //public bool check_Yuyue(long Guide_Id)
        //{
        //    using (Dbcontext ctx = new Dbcontext())
        //    {
        //        BaseService<Guide> bs = new BaseService<Guide>(ctx);
        //        var guide = bs.GetAll().Where(e => e.Id == Guide_Id).FirstOrDefault();
        //        if (guide.isappointment)
        //            return false;
        //        else
        //            return true;

        //    }
        //}

        //public bool appointment(long Tid, long userid)
        //{
        //    using (Dbcontext ctx = new Dbcontext())
        //    {
        //        try
        //        {

        //        }
        //        catch (DbEntityValidationException ex)
        //        {
        //            return false;
        //        }

        //        return true;
        //    }

        //}

        public long AddGuide(long uid, string school, string schoolnum, string picture, string intro)
        {
            Guide g = new Guide();

            g.intro         = intro;
            g.isappointment = false;
            g.level         = 1;
            g.school        = school;
            g.schoolnum     = schoolnum;
            g.picture       = picture;
            g.Users_Id      = uid;
            using (Dbcontext ctx = new Dbcontext())
            {
                ctx.Guide.Add(g);
                ctx.SaveChanges();
            }

            return(g.Id);
        }
Exemple #27
0
 public void UpdatePermIds(long roleId, long[] permIds)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Role> roleBs = new BaseService <Role>(ctx);
         var role = roleBs.GetById(roleId);
         if (role == null)
         {
             throw new ArgumentException("roleId不存在" + roleId);
         }
         role.Permissions.Clear();
         BaseService <Permission> permBs = new BaseService <Permission>(ctx);
         var perms = permBs.GetAll().Where(p => permIds.Contains(p.Id)).ToArray();
         foreach (var perm in perms)
         {
             role.Permissions.Add(perm);
         }
         ctx.SaveChanges();
     }
 }
Exemple #28
0
        public void Update(long id, string phoneNum,
                           string email, string context)
        {
            using (Dbcontext ctx = new Dbcontext())
            {
                BaseService <Comment> bs
                    = new BaseService <Comment>(ctx);

                var comment = bs.GetAll().Include(h => h.User).Include(h => h.Raiders).SingleOrDefault(h => h.Id == id);

                if (comment == null)
                {
                    throw new ArgumentException("找不到id=" + id + "的评论");
                }
                comment.User.PhoneNum = phoneNum;
                comment.User.Email    = email;
                comment.Context       = context;
                ctx.SaveChanges();
            }
        }
Exemple #29
0
 public void UpdateRoleIds(long adminUserId, long[] roleIds)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <AdminUser> userBs = new BaseService <AdminUser>(ctx);
         var user = userBs.GetById(adminUserId);
         if (user == null)
         {
             throw new ArgumentException("用户不存在" + adminUserId);
         }
         user.Roles.Clear();
         BaseService <Role> roleBs = new BaseService <Role>(ctx);
         var roles = roleBs.GetAll().Where(p => roleIds.Contains(p.Id)).ToArray();
         foreach (var role in roles)
         {
             user.Roles.Add(role);
         }
         ctx.SaveChanges();
     }
 }
Exemple #30
0
        public void AddPermIds(long roleId, long[] permIds)
        {
            using (Dbcontext ctx = new Dbcontext())
            {
                BaseService <Role> roleBs = new BaseService <Role>(ctx);
                var role = roleBs.GetById(roleId);
                if (role == null)
                {
                    throw new ArgumentException("roleId不存在" + roleId);
                }

                var permBs = ctx.Permission.Where(h => h.IsDeleted == false);
                var perms  = permBs.Where(p => permIds.Contains(p.Id)).ToArray();
                foreach (var perm in perms)
                {
                    role.Permissions.Add(perm);
                }
                ctx.SaveChanges();
            }
        }