private async Task HandleFakeTTSRequest(IRC.TwitchChatter chatter, string[] remainingCommand) { if (!enabled && chatter.User.AuthorizationLevel != AuthorizationLevel.Admin) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, I'm afraid the TTS system is currently disabled."); return; } if (chatter.User.AuthorizationLevel < AuthorizationLevel.Admin) { communication.SendPublicChatMessage($"I'm afraid I can't let you do that, @{chatter.User.TwitchUserName}."); return; } if (remainingCommand is null || remainingCommand.Length == 0) { //TTS Error communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, missing a username to fake a TTS from."); return; } string username = remainingCommand[0].ToLower(); using IServiceScope scope = scopeFactory.CreateScope(); BaseDatabaseContext db = scope.ServiceProvider.GetRequiredService <BaseDatabaseContext>(); User fakeTTSUser = db.Users.FirstOrDefault(x => x.TwitchUserName.ToLower() == username); if (fakeTTSUser is null) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, unable to find \"{username}\" in db."); return; } remainingCommand = remainingCommand[1..];
public UserInfoModel GetByOpenId(string openId) { using (var db = new BaseDatabaseContext()) { var entity = db.UserInfos.FirstOrDefault(q => q.OpenId == openId); return(entity.ToModel()); } }
public PayInfo GetHasPayedPayInfoBySerialNumber(string tradeNo) { using (var db = new BaseDatabaseContext()) { var entity = db.PayInfos.FirstOrDefault(q => q.IsPay && q.TradeNo == tradeNo); return(entity); } }
public PayInfoModel GetUnpayPayInfoBySerialNumber(string tradeNo) { using (var db = new BaseDatabaseContext()) { var entity = db.PayInfos.OrderByDescending(q => q.Id).FirstOrDefault(q => !q.IsPay && q.TradeNo == tradeNo); return(entity.ToModel()); } }
public IList <AdvertisingSpaceInfo> GetListByKeys(List <string> signs) { using (var db = new BaseDatabaseContext()) { var query = db.AdvertisingSpaceInfos.Where(q => signs.Contains(q.Sign)).OrderByDescending(q => q.Id); return(query.ToList()); } }
public void RemoveAll() { using (var db = new BaseDatabaseContext()) { var query = db.UserInfos.AsNoTracking(); query.Delete(); } }
public UserInfoModel GetLast() { using (var db = new BaseDatabaseContext()) { var entity = db.UserInfos.OrderByDescending(q => q.Id).FirstOrDefault(); return(entity.ToModel()); } }
public bool IsExistUserName(string userName) { using (var db = new BaseDatabaseContext()) { var entity = db.AdminUserInfos.FirstOrDefault(q => q.UserName == userName); return(entity != null); } }
public IList <AdvertisingSpaceInfo> GetList() { using (var db = new BaseDatabaseContext()) { var query = db.AdvertisingSpaceInfos.OrderByDescending(q => q.Id); return(query.ToList()); } }
public void TestMethod1() { var context = new BaseDatabaseContext(); var script = ((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript(); ///todo 3、 建表 第三步 生成数据库表 Assert.IsTrue(!string.IsNullOrWhiteSpace(script)); }
public IEnumerable <string> GetPublicCommands() { using IServiceScope scope = scopeFactory.CreateScope(); BaseDatabaseContext db = scope.ServiceProvider.GetRequiredService <BaseDatabaseContext>(); foreach (CustomTextCommand customTextCommand in db.CustomTextCommands.Where(x => x.Enabled)) { yield return(customTextCommand.Command); } }
public bool IsExists(int shareUserInfoId, int targetUserInfoId, int shareType) { using (var db = new BaseDatabaseContext()) { var entity = db.ShareLogInfos.FirstOrDefault(q => q.ShareUserInfoId == shareUserInfoId && q.TargetUserInfoId == targetUserInfoId && q.ShareType == (ShareType)shareType); return(entity != null); } }
public void Insert(UserInfo entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } using (var db = new BaseDatabaseContext()) { db.UserInfos.Add(entity); db.SaveChanges(); } }
public UserInfoModel GetById(int id) { using (var db = new BaseDatabaseContext()) { var entity = db.UserInfos.Find(id); if (entity == null) { return(null); } return(entity.ToModel()); } }
public AdvContentInfoModel GetById(int id) { using (var db = new BaseDatabaseContext()) { var entity = db.AdvContentInfos.FirstOrDefault(q => q.Id == id); if (entity == null) { return(null); } return(entity.ToModel()); } }
public void Delete(int id) { using (var db = new BaseDatabaseContext()) { var entity = db.UserInfos.Find(id); if (entity == null) { throw new Exception("entity is null"); } db.UserInfos.Remove(entity); db.SaveChanges(); } }
public void Delete(int id) { using (var db = new BaseDatabaseContext()) { var entity = db.AdvContentInfos.FirstOrDefault(q => q.Id == id); if (entity == null) { throw new Exception("entity is null"); } db.AdvContentInfos.Remove(entity); db.SaveChanges(); } }
public AdminUserInfoModel GetByUserName(string userName) { using (var db = new BaseDatabaseContext()) { var entity = db.AdminUserInfos.FirstOrDefault(q => q.UserName == userName); if (entity != null) { return(entity.ToModel()); } else { return(null); } } }
public string GetShareNickNameById(int id) { using (var db = new BaseDatabaseContext()) { var entity = db.ShareLogInfos.FirstOrDefault(q => q.Id == id); if (entity != null) { return(entity.ShareUserInfo.NickName); } else { return(string.Empty); } } }
public IPageList <AdminUserInfo> GetPageList(int page, int size, string userName) { using (var db = new BaseDatabaseContext()) { var query = db.AdminUserInfos.AsNoTracking().AsQueryable(); if (!string.IsNullOrEmpty(userName)) { query = query.Where(q => q.UserName.Contains(userName)); } query = query.OrderByDescending(q => q.Id); return(new PageList <AdminUserInfo>(query, page, size)); } }
public IPageList <AdvertisingSpaceInfo> GetPageList(int page, int size, string title) { using (var db = new BaseDatabaseContext()) { var query = db.AdvertisingSpaceInfos.AsQueryable(); if (!string.IsNullOrEmpty(title)) { query = query.Where(q => q.Title.Contains(title)); } query = query.OrderByDescending(q => q.Id); return(new PageList <AdvertisingSpaceInfo>(query, page, size)); } }
public void Update(AdvertisingSpaceInfoModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } using (var db = new BaseDatabaseContext()) { var oldEntity = db.AdvertisingSpaceInfos.FirstOrDefault(q => q.Id == model.Id); if (oldEntity == null) { throw new Exception("oldEntity is null"); } oldEntity = model.ToEntity(oldEntity); db.SaveChanges(); } }
public void Update(UserInfoModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } using (var db = new BaseDatabaseContext()) { var oldEntity = db.UserInfos.Find(model.Id); if (oldEntity == null) { throw new Exception("oldEntity is null"); } oldEntity = model.ToEntity(oldEntity); db.SaveChanges(); } }
public void SetLoginInfo(string userName, string ip) { if (!string.IsNullOrEmpty(userName)) { using (var db = new BaseDatabaseContext()) { var entity = db.AdminUserInfos.FirstOrDefault(q => q.UserName == userName); if (entity != null) { var model = entity.ToModel(); model.LastLoginDate = DateTime.Now; model.LoginSuccessTimes = model.LoginSuccessTimes + 1; model.LastLoginIp = ip; Update(model); } } } }
public IPageList <AdvContentInfo> GetPageList(int page, int size, string contentJsonKeyword, string advertisingSpaceInfoSign) { using (var db = new BaseDatabaseContext()) { var query = db.AdvContentInfos.AsQueryable(); if (!string.IsNullOrEmpty(contentJsonKeyword)) { query = query.Where(q => q.ContentJsonKeyword.Contains(contentJsonKeyword)); } if (!string.IsNullOrEmpty(advertisingSpaceInfoSign)) { query = query.Where(q => q.AdvertisingSpaceInfoSign == advertisingSpaceInfoSign); } query = query.OrderByDescending(q => q.Id); return(new PageList <AdvContentInfo>(query, page, size)); } }
public void RegisterCommands( Dictionary <string, CommandHandler> commands, Dictionary <string, HelpFunction> helpFunctions, Dictionary <string, SetFunction> setFunctions, Dictionary <string, GetFunction> getFunctions) { commands.Add("add", AddCommand); commands.Add("remove", RemoveCommand); commands.Add("edit", EditCommand); commands.Add("enable", async(chatter, remainingCommand) => await SetCommandState(chatter, remainingCommand, true)); commands.Add("disable", async(chatter, remainingCommand) => await SetCommandState(chatter, remainingCommand, false)); using IServiceScope scope = scopeFactory.CreateScope(); BaseDatabaseContext db = scope.ServiceProvider.GetRequiredService <BaseDatabaseContext>(); foreach (CustomTextCommand customTextCommand in db.CustomTextCommands.Where(x => x.Enabled)) { commands.Add(customTextCommand.Command, async(chatter, remainingCommand) => await HandleCommand(customTextCommand.Text)); } //We cache a reference to the commands dictionary to add to it later: commandsCache = commands; }
private async Task AdjustUser(IRC.TwitchChatter chatter, string[] remainingCommand, bool elevate) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Moderator) { //Moderators and Admins can adjust users communication.SendPublicChatMessage($"I'm afraid I can't let you do that, @{chatter.User.TwitchUserName}."); return; } if (remainingCommand == null || remainingCommand.Length == 0) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, {(elevate ? "Elevate" : "Demote")} who?"); return; } string lowerUser = remainingCommand[0].ToLower(); if (string.IsNullOrWhiteSpace(lowerUser)) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, {(elevate ? "Elevate" : "Demote")} who?"); return; } using IServiceScope scope = scopeFactory.CreateScope(); BaseDatabaseContext db = scope.ServiceProvider.GetRequiredService <BaseDatabaseContext>(); IEnumerable <User> matchingUsers = db.Users.Where(x => x.TwitchUserName.ToLower() == lowerUser); if (!matchingUsers.Any()) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {remainingCommand[0]} not found."); return; } if (matchingUsers.Count() > 1) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {remainingCommand[0]} found multiple times."); return; } User matchingUser = matchingUsers.First(); if (elevate) { if (matchingUser.AuthorizationLevel == AuthorizationLevel.Restricted) { //Unrestricting a user matchingUser.AuthorizationLevel = AuthorizationLevel.None; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} no longer restricted."); } else if (matchingUser.AuthorizationLevel == AuthorizationLevel.None) { matchingUser.AuthorizationLevel = AuthorizationLevel.Elevated; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} has been elevated!"); } else { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} is already fully elevated."); } } else { if (matchingUser.AuthorizationLevel == AuthorizationLevel.Elevated) { matchingUser.AuthorizationLevel = AuthorizationLevel.None; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} has been demoted!"); } else if (matchingUser.AuthorizationLevel == AuthorizationLevel.None) { matchingUser.AuthorizationLevel = AuthorizationLevel.Restricted; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} has been restricted!"); } else { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} can't be further demoted."); } } }
protected Repository(BaseDatabaseContext databaseContext) : base(databaseContext) { }
public WaterMetersService(BaseDatabaseContext dbContext) { _dbContext = dbContext; }
protected BaseRepository(BaseDatabaseContext databaseContext) { DatabaseContext = databaseContext; }