Esempio n. 1
0
        public long AddNew(AdminUserAddDto model)
        {
            AdminUserEntity adminUser = model.EntityMap();

            string pwdHash = "123456".CalcMd5();

            adminUser.PasswordHash   = pwdHash;
            adminUser.CreateDateTime = DateTime.Now;

            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <AdminUserEntity> bs
                    = new BaseService <AdminUserEntity>(ctx);
                ctx.AdminUsers.Add(adminUser);

                bool exists = bs.GetAll().Any(u => u.LoginName == model.LoginName);

                if (exists)
                {
                    throw new ArgumentException("登录名已经存在" + model.LoginName);
                }

                ctx.AdminUsers.Add(adminUser);
                ctx.SaveChanges();
                return(adminUser.Id);
            }
        }
        public long AddNew(VideoDetailAddDto dto)
        {
            dto.CreateDateTime = DateTime.Now;
            if (dto.Content == null)
            {
                dto.Content = "";
            }
            VideoDetailEntity videoDetail = dto.EntityMap();

            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoDetailEntity> bs
                    = new BaseService <VideoDetailEntity>(ctx);

                if (bs.GetAll().Any(m => m.VideoDetailName == videoDetail.VideoDetailName))
                {
                    throw new ArgumentException("该视频标题已存在,请检查");
                }

                ctx.VideoDetails.Add(videoDetail);

                ctx.SaveChanges();

                return(videoDetail.Id);
            }
        }
Esempio n. 3
0
        public void Update(VideoAddDto dto)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoEntity> bs
                    = new BaseService <VideoEntity>(ctx);

                bool exists = bs.GetAll().Any(u => u.Title == dto.Title && u.Id != dto.Id);

                if (exists)
                {
                    throw new ArgumentException("该视频已经存在:" + dto.Title);
                }
                var entity = dto.EntityMap();

                DbEntityEntry <VideoEntity> entry = ctx.Entry <VideoEntity>(entity);
                entry.State = EntityState.Modified;
                ctx.SaveChanges();

                //ctx.Videos.Attach(entity);
                //ctx.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);

                //ctx.SaveChanges();
            }
        }
Esempio n. 4
0
        public long AddNew(UserAddDto dto)
        {
            UserEntity user = dto.EntityMap();

            var model = GetByOpenId(dto.AccountNumber);

            user.CreateDateTime = DateTime.Now;
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <UserEntity> bs
                    = new BaseService <UserEntity>(ctx);
                if (model == null || model.Id <= 0)
                {
                    ctx.Users.Add(user);
                }
                else
                {
                    var updateModel = bs.GetById(model.Id);
                    updateModel.UserName          = user.UserName;
                    updateModel.HeadPortraitSrc   = user.HeadPortraitSrc;
                    updateModel.AccountNumber     = user.AccountNumber;
                    updateModel.LastLoginDateTime = DateTime.Now;
                    updateModel.Sex = user.Sex;
                }

                ctx.SaveChanges();

                return(user.Id);
            }
        }
Esempio n. 5
0
        public AdminLogDto[] GetPagedData(string message, string ip, DateTime?begin, DateTime?end, int adminUserId, out int total, int page = 1,
                                          int limit = 10)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <AdminLogEntity> adminLogBaseService = new BaseService <AdminLogEntity>(ctx);
                var adminLog = adminLogBaseService.GetAll()
                               .Where(a => a.Message.Contains(message) && a.OperIp.Contains(ip) && !a.IsDeleted);
                if (adminUserId > 0)
                {
                    adminLog = adminLog.Where(m => m.AdminUserId == adminUserId);
                }
                if (begin != null)
                {
                    adminLog = adminLog.Where(m => m.CreateDateTime >= begin);
                }
                if (end != null)
                {
                    adminLog = adminLog.Where(m => m.CreateDateTime <= end);
                }

                total = adminLog.Count();

                var adminLogList = adminLog.OrderByDescending(a => a.CreateDateTime)
                                   .Skip(limit * (page - 1)).Take(limit).ToList().Select(h => h.EntityMap()).ToArray();

                return(adminLogList);
            }
        }
Esempio n. 6
0
        public UserDto GetById(long id)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <UserEntity> baseService = new BaseService <UserEntity>(ctx);

                return(baseService.GetById(id).EntityMap());
            }
        }
Esempio n. 7
0
 public void MarkDeleted(long id)
 {
     using (YersDbContext ctx = new YersDbContext())
     {
         BaseService <VideoEntity> bs
             = new BaseService <VideoEntity>(ctx);
         bs.MarkDeleted(id);
     }
 }
Esempio n. 8
0
        public IdNameDto GetById(long id)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <IdNameEntity> idNameBaseService = new BaseService <IdNameEntity>(ctx);

                return(idNameBaseService.GetById(id).EntityMap());
            }
        }
Esempio n. 9
0
        public VideoAddDto GetById(long id)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoEntity> videoService = new BaseService <VideoEntity>(ctx);

                return(videoService.GetById(id).EntityMap());
            }
        }
Esempio n. 10
0
        public bool Exist(string openId)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <UserEntity> bs
                    = new BaseService <UserEntity>(ctx);

                return(bs.GetAll().Any(m => m.AccountNumber == openId));
            }
        }
Esempio n. 11
0
        public VideoListDto[] GetAll()
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoEntity> videoBaseService = new BaseService <VideoEntity>(ctx);
                var videoDto = videoBaseService.GetAll()
                               .Where(a => !a.IsDeleted).ToList();

                return(videoDto.Select(h => h.EntityMapToList()).ToArray());
            }
        }
Esempio n. 12
0
        public UserDto[] GetAll()
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <UserEntity> bs
                    = new BaseService <UserEntity>(ctx);

                var list = bs.GetAll().ToArray();
                return(Mapper.Map <UserEntity[], UserDto[]>(list));
            }
        }
Esempio n. 13
0
        public UserDto GetByOpenId(string openId)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <UserEntity> baseService = new BaseService <UserEntity>(ctx);

                var model = baseService.GetAll().FirstOrDefault(m => m.AccountNumber == openId);
                model = model ?? new UserEntity();
                return(model.EntityMap());
            }
        }
Esempio n. 14
0
        public VideoDetailListDto[] GetVideoDetailList(long videoId)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoDetailEntity> bs
                    = new BaseService <VideoDetailEntity>(ctx);

                var videlDetail = bs.GetAll().Where(m => m.VideoId == videoId).ToList();

                return(videlDetail.Select(h => h.EntityMapToList()).ToArray());
            }
        }
Esempio n. 15
0
        public IdNameDto[] GetByTypeName(string typeName)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <IdNameEntity> idNameBaseService = new BaseService <IdNameEntity>(ctx);
                var idNameList = idNameBaseService.GetAll()
                                 .Where(a => a.TypeName == typeName && !a.IsDeleted)
                                 .ToList().Select(h => h.EntityMap()).ToArray();

                return(idNameList);
            }
        }
Esempio n. 16
0
        public void UpdateImage(int id, string fileName)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <IdNameEntity> bs
                    = new BaseService <IdNameEntity>(ctx);

                var model = bs.GetById(id);

                model.ImageSrc = fileName;
                ctx.SaveChanges();
            }
        }
Esempio n. 17
0
        public IdNameDto[] GetPagedData(string name, string typeName, out int total, int page = 1, int limit = 10)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <IdNameEntity> idNameBaseService = new BaseService <IdNameEntity>(ctx);
                var idNameDto = idNameBaseService.GetAll()
                                .Where(a => a.Name.Contains(name) && a.TypeName.Contains(typeName) && !a.IsDeleted);

                total = idNameDto.Count();

                var idNameList = idNameDto.OrderBy(a => a.CreateDateTime)
                                 .Skip(limit * (page - 1)).Take(limit).ToList().Select(h => h.EntityMap()).ToArray();

                return(idNameList);
            }
        }
Esempio n. 18
0
        public VideoListDto[] GetPagedData(string title, out int total, int page, int limit)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoEntity> videoBaseService = new BaseService <VideoEntity>(ctx);
                var videoDto = videoBaseService.GetAll()
                               .Where(a => a.Title.Contains(title) && !a.IsDeleted);

                total = videoDto.Count();

                var videoList = videoDto.OrderBy(a => a.CreateDateTime)
                                .Skip(limit * (page - 1)).Take(limit).ToList();

                return(videoList.Select(h => h.EntityMapToList()).ToArray());
            }
        }
Esempio n. 19
0
        public AdminUserDto[] GetPagedData(string userName, string loginName, string phone, string email, out int total, int page = 1,
                                           int limit = 10)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <AdminUserEntity> adminBaseService = new BaseService <AdminUserEntity>(ctx);
                var adminDto = adminBaseService.GetAll()
                               .Where(a => a.UserName.Contains(userName) && a.LoginName.Contains(loginName) && a.Email.Contains(email) && a.PhoneNumber.Contains(phone) && !a.IsDeleted);

                total = adminDto.Count();

                var adminList = adminDto.OrderBy(a => a.CreateDateTime)
                                .Skip(limit * (page - 1)).Take(limit).ToList().Select(h => h.EntityMap()).ToArray();

                return(adminList);
            }
        }
Esempio n. 20
0
        public AdminUserDto Login(string loginName, string loginPwd)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <AdminUserEntity> adminBaseService = new BaseService <AdminUserEntity>(ctx);

                var password = loginPwd.CalcMd5();

                if (!adminBaseService.GetAll()
                    .Any(m => m.LoginName == loginName && m.PasswordHash == password && !m.IsDeleted))
                {
                    return(new AdminUserDto());
                }

                return(adminBaseService.GetAll()
                       .FirstOrDefault(m => m.LoginName == loginName && m.PasswordHash == password && !m.IsDeleted)
                       .EntityMap());
            }
        }
Esempio n. 21
0
        public void Update(VideoDetailAddDto dto)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoDetailEntity> bs
                    = new BaseService <VideoDetailEntity>(ctx);

                bool exists = bs.GetAll().Any(u => u.VideoDetailName == dto.VideoDetailName && u.Id != dto.Id);

                if (exists)
                {
                    throw new ArgumentException("该视频已经存在:" + dto.VideoDetailName);
                }
                var entity = dto.EntityMap();

                DbEntityEntry <VideoDetailEntity> entry = ctx.Entry <VideoDetailEntity>(entity);
                entry.State = EntityState.Modified;
                ctx.SaveChanges();
            }
        }
Esempio n. 22
0
        public long AddNew(IdNameDto model)
        {
            IdNameEntity idNameEntity = model.EntityMap();

            idNameEntity.CreateDateTime = DateTime.Now;
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <IdNameEntity> bs
                    = new BaseService <IdNameEntity>(ctx);

                if (bs.GetAll().Any(m => m.TypeName == idNameEntity.TypeName && m.Name == idNameEntity.Name))
                {
                    throw new ArgumentException("该数据已存在,请检查");
                }

                ctx.IdNames.Add(idNameEntity);

                ctx.SaveChanges();

                return(idNameEntity.Id);
            }
        }
Esempio n. 23
0
        public long AddNew(string message)
        {
            AdminLogEntity adminLogEntity = new AdminLogEntity
            {
                CreateDateTime = DateTime.Now,
                OperIp         = CommonHelper.GetHostAddress(),
                Message        = message,
                AdminUserId    = int.Parse(HttpContext.Current.Session[Keys.AdminId].ToString())
            };

            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <AdminLogEntity> bs
                    = new BaseService <AdminLogEntity>(ctx);

                ctx.AdminLogs.Add(adminLogEntity);

                ctx.SaveChanges();

                return(adminLogEntity.Id);
            }
        }
Esempio n. 24
0
        public void Add(string key, string value)
        {
            using (YersDbContext db = new YersDbContext())
            {
                BaseService <SettingEntity> bs = new BaseService <SettingEntity>(db);

                if (db.Settings.Any(m => m.Name == key))
                {
                    throw new ArgumentException("参数名称已经存在");
                }

                SettingEntity model = new SettingEntity()
                {
                    Name  = key,
                    Value = value
                };

                db.Settings.Add(model);

                db.SaveChanges();
            }
        }
Esempio n. 25
0
        public long AddNew(VideoAddDto dto)
        {
            VideoEntity videoEntity = dto.EntityMap();

            videoEntity.CreateDateTime = DateTime.Now;
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoEntity> bs
                    = new BaseService <VideoEntity>(ctx);

                if (bs.GetAll().Any(m => m.Title == videoEntity.Title))
                {
                    throw new ArgumentException("该视频标题已存在,请检查");
                }

                ctx.Videos.Add(videoEntity);

                ctx.SaveChanges();

                return(videoEntity.Id);
            }
        }
Esempio n. 26
0
        public void Update(IdNameDto dto)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <IdNameEntity> bs
                    = new BaseService <IdNameEntity>(ctx);

                bool exists = bs.GetAll().Any(m => m.TypeName == dto.TypeName && m.Name == dto.Name && m.Id != dto.Id);;

                if (exists)
                {
                    throw new ArgumentException("该数据已存在,请检查");
                }

                var model = bs.GetById(dto.Id);

                model.Name     = dto.Name;
                model.TypeName = dto.TypeName;
                model.ImageSrc = dto.ImageSrc;
                model.Remark   = dto.Remark;

                ctx.SaveChanges();
            }
        }
Esempio n. 27
0
        public void Update(AdminUserAddDto dto)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <AdminUserEntity> bs
                    = new BaseService <AdminUserEntity>(ctx);

                bool exists = bs.GetAll().Any(u => u.LoginName == dto.LoginName && u.Id != dto.Id);

                if (exists)
                {
                    throw new ArgumentException("登录名已经存在" + dto.LoginName);
                }

                var model = bs.GetById(dto.Id);

                model.LoginName   = dto.LoginName;
                model.UserName    = dto.UserName;
                model.Email       = dto.Email;
                model.PhoneNumber = dto.PhoneNumber;

                ctx.SaveChanges();
            }
        }
Esempio n. 28
0
 public BaseService(YersDbContext db)
 {
     this._db = db;
 }