private bool getDashboardStatus(Message message) { DashboardUserLogic dul = new DashboardUserLogic(); DashboardUser user = dul.GetByTelegramUserId(message.From.Id); if (user == null) { return(false); } DashboardPermissionLogic dpl = new DashboardPermissionLogic(); DashboardPermission permission = dpl.GetByUserId(user.DashboardUserId, CacheData.Groups[message.Chat.Id].GroupId); if (permission == null) { return(false); } if (permission.State == DashboardPermission.Status.Active) { return(true); } return(false); }
public DashboardPermission Update(DashboardPermission dashboardPermission, int callerId) { using (UBContext ubc = new UBContext()) { DashboardPermission exists = ubc.Group_DashboardPermissions .Where(x => x.DashboardPermissionId == dashboardPermission.DashboardPermissionId) .FirstOrDefault(); if (exists == null) { return(null); } try { exists.GroupId = dashboardPermission.GroupId; exists.State = dashboardPermission.State; exists.LastUpdateUtc = dashboardPermission.LastUpdateUtc; ubc.SaveChanges(); return(dashboardPermission); } catch (Exception ex) { Utils.Logging.AddLog(new SystemLog() { LoggerName = "Unifiedban", Date = DateTime.Now, Function = "Unifiedban.Data.DashboardPermissionService.Update", Level = SystemLog.Levels.Warn, Message = ex.Message, UserId = callerId }); if (ex.InnerException != null) { Utils.Logging.AddLog(new SystemLog() { LoggerName = "Unifiedban.Data", Date = DateTime.Now, Function = "Unifiedban.Data.DashboardPermissionService.Update", Level = SystemLog.Levels.Warn, Message = ex.InnerException.Message, UserId = callerId }); } } return(null); } }
public SystemLog.ErrorCodes Remove(DashboardPermission dashboardPermission, int callerId) { using (UBContext ubc = new UBContext()) { DashboardPermission exists = ubc.Group_DashboardPermissions .Where(x => x.DashboardPermissionId == dashboardPermission.DashboardPermissionId) .FirstOrDefault(); if (exists == null) { return(SystemLog.ErrorCodes.Error); } try { ubc.SaveChanges(); return(SystemLog.ErrorCodes.OK); } catch (Exception ex) { Utils.Logging.AddLog(new SystemLog() { LoggerName = "Unifiedban", Date = DateTime.Now, Function = "Unifiedban.Data.DashboardPermissionService.Remove", Level = SystemLog.Levels.Warn, Message = ex.Message, UserId = callerId }); if (ex.InnerException != null) { Utils.Logging.AddLog(new SystemLog() { LoggerName = "Unifiedban.Data", Date = DateTime.Now, Function = "Unifiedban.Data.DashboardPermissionService.Remove", Level = SystemLog.Levels.Warn, Message = ex.InnerException.Message, UserId = callerId }); } } return(SystemLog.ErrorCodes.Error); } }
public DashboardPermission Add(DashboardPermission dashboardPermission, int callerId) { using (UBContext ubc = new UBContext()) { try { ubc.Add(dashboardPermission); ubc.SaveChanges(); return(dashboardPermission); } catch (Exception ex) { Utils.Logging.AddLog(new SystemLog() { LoggerName = "Unifiedban", Date = DateTime.Now, Function = "Unifiedban.Data.DashboardPermissionService.Add", Level = SystemLog.Levels.Warn, Message = ex.Message, UserId = callerId }); if (ex.InnerException != null) { Utils.Logging.AddLog(new SystemLog() { LoggerName = "Unifiedban.Data", Date = DateTime.Now, Function = "Unifiedban.Data.DashboardPermissionService.Add", Level = SystemLog.Levels.Warn, Message = ex.InnerException.Message, UserId = callerId }); } } return(null); } }
private void toggleDashboard(CallbackQuery callbackQuery) { Message message = callbackQuery.Message; DashboardUserLogic dul = new DashboardUserLogic(); DashboardUser user = dul.GetByTelegramUserId(callbackQuery.From.Id); if (user == null) { string profilePic = ""; var photos = Manager.BotClient.GetUserProfilePhotosAsync(callbackQuery.From.Id).Result; if (photos.TotalCount > 0) { profilePic = photos.Photos[0][0].FileId; } user = dul.Add(callbackQuery.From.Id, callbackQuery.From.FirstName + " " + callbackQuery.From.LastName, profilePic, -2); if (user == null) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = "*[Report]*\n" + "Error enabling dashboard!" }); return; } } DashboardPermissionLogic dpl = new DashboardPermissionLogic(); DashboardPermission permission = dpl.GetByUserId(user.DashboardUserId, CacheData.Groups[message.Chat.Id].GroupId); if (permission == null) { if (dpl.Add(CacheData.Groups[message.Chat.Id].GroupId, user.DashboardUserId, DashboardPermission.Status.Active, -2) == null) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = "*[Report]*\n" + "Error enabling dashboard!" }); return; } MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = "Dashboard enabled!" }); callbackQuery.Message.From.Id = callbackQuery.From.Id; Execute(callbackQuery.Message, true); return; } if (permission.State == DashboardPermission.Status.Banned) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = "*[Report]*\n" + "Error: you are banned from the dashboard!" }); return; } else if (permission.State == DashboardPermission.Status.Active) { permission.State = DashboardPermission.Status.Inactive; } else if (permission.State == DashboardPermission.Status.Inactive) { permission.State = DashboardPermission.Status.Active; } if (dpl.Update(permission, -2) == null) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = "*[Report]*\n" + "Error enabling dashboard!" }); } else { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = "Dashboard status updated!" }); callbackQuery.Message.From.Id = callbackQuery.From.Id; Execute(callbackQuery.Message, true); } }