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); } }
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(); } }
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); } }
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); } }
public UserDto GetById(long id) { using (YersDbContext ctx = new YersDbContext()) { BaseService <UserEntity> baseService = new BaseService <UserEntity>(ctx); return(baseService.GetById(id).EntityMap()); } }
public void MarkDeleted(long id) { using (YersDbContext ctx = new YersDbContext()) { BaseService <VideoEntity> bs = new BaseService <VideoEntity>(ctx); bs.MarkDeleted(id); } }
public IdNameDto GetById(long id) { using (YersDbContext ctx = new YersDbContext()) { BaseService <IdNameEntity> idNameBaseService = new BaseService <IdNameEntity>(ctx); return(idNameBaseService.GetById(id).EntityMap()); } }
public VideoAddDto GetById(long id) { using (YersDbContext ctx = new YersDbContext()) { BaseService <VideoEntity> videoService = new BaseService <VideoEntity>(ctx); return(videoService.GetById(id).EntityMap()); } }
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)); } }
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()); } }
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)); } }
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()); } }
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()); } }
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); } }
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(); } }
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); } }
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()); } }
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); } }
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()); } }
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(); } }
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); } }
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); } }
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(); } }
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); } }
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(); } }
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(); } }
public BaseService(YersDbContext db) { this._db = db; }