Exemplo n.º 1
0
        public List <Banned> GetLimit(Expression <Func <Banned, bool> > whereClause, int limit)
        {
            try
            {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.Users_Banned
                               .AsNoTracking()
                               .OrderByDescending(x => x.UtcDate).Skip(0).Take(limit)
                               .ToList());
                    }

                    return(ubc.Users_Banned
                           .AsNoTracking()
                           .Where(whereClause)
                           .OrderByDescending(x => x.UtcDate).Skip(0).Take(limit)
                           .ToList());
                }
            }
            catch
            {
                return(new List <Banned>());
            }
        }
Exemplo n.º 2
0
        public TelegramGroup Update(TelegramGroup telegramGroup, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                TelegramGroup exists = ubc.Group_TelegramGroups
                                       .Where(x => x.GroupId == telegramGroup.GroupId)
                                       .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.TelegramChatId   = telegramGroup.TelegramChatId;
                    exists.Title            = telegramGroup.Title;
                    exists.State            = telegramGroup.State;
                    exists.Configuration    = telegramGroup.Configuration;
                    exists.WelcomeText      = telegramGroup.WelcomeText;
                    exists.ChatLanguage     = telegramGroup.ChatLanguage;
                    exists.SettingsLanguage = telegramGroup.SettingsLanguage;
                    exists.ReportChatId     = telegramGroup.ReportChatId;
                    exists.RulesText        = telegramGroup.RulesText;

                    ubc.SaveChanges();
                    return(telegramGroup);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.TelegramGroupService.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.TelegramGroupService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Exemplo n.º 3
0
        public BadImage Update(BadImage badImage, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                BadImage exists = ubc.BadImages
                                  .Where(x => x.BadImageId == badImage.BadImageId)
                                  .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.GroupId       = badImage.GroupId;
                    exists.HashData      = badImage.HashData;
                    exists.ParentImageId = badImage.ParentImageId;
                    exists.FlipType      = badImage.FlipType;
                    exists.Status        = badImage.Status;
                    exists.Match         = badImage.Match;

                    ubc.SaveChanges();
                    return(badImage);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.BadImageService.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.BadImageService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Exemplo n.º 4
0
        public BadWord Update(BadWord badWord, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                BadWord exists = ubc.BadWords
                                 .Where(x => x.BadWordId == badWord.BadWordId)
                                 .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.Name    = badWord.Name;
                    exists.GroupId = badWord.GroupId;
                    exists.Regex   = badWord.Regex;
                    exists.Status  = badWord.Status;
                    exists.Match   = badWord.Match;

                    ubc.SaveChanges();
                    return(badWord);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.BadWordService.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.BadWordService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Exemplo n.º 5
0
        public SafeTName Update(SafeTName safeTName,
                                SafeTName newSafeTName, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                SafeTName exists = ubc.SafeTNames
                                   .Where(x => x.Username == safeTName.Username &&
                                          x.TelegramChatId == safeTName.TelegramChatId)
                                   .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.Username       = newSafeTName.Username;
                    exists.TelegramChatId = newSafeTName.TelegramChatId;

                    ubc.SaveChanges();
                    return(safeTName);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.SafeTNameService.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.SafeTNameService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Exemplo n.º 6
0
        public NightSchedule Update(NightSchedule nightSchedule, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                NightSchedule exists = ubc.Group_NightSchedules
                                       .Where(x => x.GroupId == nightSchedule.GroupId)
                                       .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.State        = nightSchedule.State;
                    exists.UtcStartDate = nightSchedule.UtcStartDate;
                    exists.UtcEndDate   = nightSchedule.UtcEndDate;

                    ubc.SaveChanges();
                    return(nightSchedule);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.NightScheduleService.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.NightScheduleService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Exemplo n.º 7
0
        public Flood Update(Flood flood, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                Flood exists = ubc.Users_Flood
                               .Where(x => x.GroupId == flood.GroupId &&
                                      x.TelegramUserId == flood.TelegramUserId)
                               .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.MessageCount = flood.MessageCount;
                    exists.UtcDate      = flood.UtcDate;

                    ubc.SaveChanges();
                    return(flood);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.FloodService.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.FloodService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Exemplo n.º 8
0
        public DashboardUser Update(DashboardUser dashboardUser, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                DashboardUser exists = ubc.Group_DashboardUsers
                                       .Where(x => x.DashboardUserId == dashboardUser.DashboardUserId)
                                       .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.Name           = dashboardUser.Name;
                    exists.ProfilePicture = dashboardUser.ProfilePicture;
                    exists.LastActionUtc  = dashboardUser.LastActionUtc;

                    ubc.SaveChanges();
                    return(dashboardUser);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.DashboardUserService.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.DashboardUserService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Exemplo n.º 9
0
        public ConfigurationParameter Update(ConfigurationParameter configurationParameter, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                ConfigurationParameter exists = ubc.Group_ConfigurationParameters
                                                .Where(x => x.ConfigurationParameterId == configurationParameter.ConfigurationParameterId)
                                                .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.Value  = configurationParameter.Value;
                    exists.Type   = configurationParameter.Type;
                    exists.Values = configurationParameter.Values;

                    ubc.SaveChanges();
                    return(configurationParameter);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.ConfigurationParameterService.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.ConfigurationParameterService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Exemplo n.º 10
0
        public Note Update(Note note, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                Note exists = ubc.Group_Notes
                              .Where(x => x.NoteId == note.NoteId)
                              .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.GroupId = note.GroupId;
                    exists.Message = note.Message;
                    exists.Tag     = note.Tag;

                    ubc.SaveChanges();
                    return(note);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.NoteService.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.NoteService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Exemplo n.º 11
0
        public TrustFactor Update(TrustFactor trustFactor, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                TrustFactor exists = ubc.Users_TrustFactor
                                     .Where(x => x.TrustFactorId == trustFactor.TrustFactorId)
                                     .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.Points = trustFactor.Points;

                    ubc.SaveChanges();
                    return(trustFactor);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.TrustFactorService.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.TrustFactorService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Exemplo n.º 12
0
        public SystemLog.ErrorCodes Remove(SafeGroup safeGroup, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                SafeGroup exists = ubc.Group_SafeGroups
                                   .Where(x => x.GroupId == safeGroup.GroupId)
                                   .FirstOrDefault();
                if (exists == null)
                {
                    return(SystemLog.ErrorCodes.Error);
                }

                try
                {
                    ubc.Remove(exists);
                    ubc.SaveChanges();
                    return(SystemLog.ErrorCodes.OK);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.SafeGroupService.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.SafeGroupService.Remove",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(SystemLog.ErrorCodes.Error);
            }
        }
Exemplo n.º 13
0
 public SafeGroup Add(SafeGroup safeGroup, int callerId)
 {
     using (UBContext ubc = new UBContext())
     {
         try
         {
             ubc.Add(safeGroup);
             ubc.SaveChanges();
             return(safeGroup);
         }
         catch (Exception ex)
         {
             Utils.Logging.AddLog(new SystemLog()
             {
                 LoggerName = "Unifiedban",
                 Date       = DateTime.Now,
                 Function   = "Unifiedban.Data.SafeGroupService.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.SafeGroupService.Add",
                     Level      = SystemLog.Levels.Warn,
                     Message    = ex.InnerException.Message,
                     UserId     = callerId
                 });
             }
         }
         return(null);
     }
 }
Exemplo n.º 14
0
        public List <SafeGroup> Get(Expression <Func <SafeGroup, bool> > whereClause)
        {
            try
            {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.Group_SafeGroups
                               .AsNoTracking()
                               .ToList());
                    }

                    return(ubc.Group_SafeGroups
                           .AsNoTracking()
                           .Where(whereClause)
                           .ToList());
                }
            }
            catch
            {
                return(new List <SafeGroup>());
            }
        }
Exemplo n.º 15
0
        public List <NightSchedule> Get(Expression <Func <NightSchedule, bool> > whereClause)
        {
            try
            {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.Group_NightSchedules
                               .AsNoTracking()
                               .ToList());
                    }

                    return(ubc.Group_NightSchedules
                           .AsNoTracking()
                           .Where(whereClause)
                           .ToList());
                }
            }
            catch
            {
                return(new List <NightSchedule>());
            }
        }
Exemplo n.º 16
0
        public List <ConfigurationParameter> Get(Expression <Func <ConfigurationParameter, bool> > whereClause)
        {
            try
            {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.Group_ConfigurationParameters
                               .AsNoTracking()
                               .ToList());
                    }

                    return(ubc.Group_ConfigurationParameters
                           .AsNoTracking()
                           .Where(whereClause)
                           .ToList());
                }
            }
            catch
            {
                return(new List <ConfigurationParameter>());
            }
        }
Exemplo n.º 17
0
        public List <DashboardUser> Get(Expression <Func <DashboardUser, bool> > whereClause)
        {
            try
            {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.Group_DashboardUsers
                               .AsNoTracking()
                               .ToList());
                    }

                    return(ubc.Group_DashboardUsers
                           .AsNoTracking()
                           .Where(whereClause)
                           .ToList());
                }
            }
            catch
            {
                return(new List <DashboardUser>());
            }
        }
Exemplo n.º 18
0
        public List <TrustFactor> Get(Expression <Func <TrustFactor, bool> > whereClause)
        {
            try
            {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.Users_TrustFactor
                               .AsNoTracking()
                               .ToList());
                    }

                    return(ubc.Users_TrustFactor
                           .AsNoTracking()
                           .Where(whereClause)
                           .ToList());
                }
            }
            catch
            {
                return(new List <TrustFactor>());
            }
        }
Exemplo n.º 19
0
        public List <BadImage> Get(Expression <Func <BadImage, bool> > whereClause)
        {
            try
            {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.BadImages
                               .AsNoTracking()
                               .ToList());
                    }

                    return(ubc.BadImages
                           .AsNoTracking()
                           .Where(whereClause)
                           .ToList());
                }
            }
            catch
            {
                return(new List <BadImage>());
            }
        }
Exemplo n.º 20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, UBContext db)
        {
            app.UseExceptionScheme(env)
            .UseSwaggerService();
            loggerFactory.AddNLog();
            //AutoMapperHandler.UseAutoMapper();

            app.UseHttpsRedirection();
            app.UseMvc();

            db.InitSeed();
        }
Exemplo n.º 21
0
 public UserRepository(UBContext ubContext)
 {
     db = ubContext;
 }
Exemplo n.º 22
0
        public Banned Add(Banned banned, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                try
                {
                    using (var transaction = ubc.Database.BeginTransaction())
                    {
                        try
                        {
                            ubc.Add(banned);
                            ubc.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.User_Banned ON;");
                            ubc.SaveChanges();
                            ubc.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.User_Banned OFF");
                            transaction.Commit();

                            return(banned);
                        }
                        catch (Exception ex)
                        {
                            Utils.Logging.AddLog(new SystemLog()
                            {
                                LoggerName = "Unifiedban",
                                Date       = DateTime.Now,
                                Function   = "Unifiedban.Data.BannedService.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.BannedService.Add",
                                    Level      = SystemLog.Levels.Warn,
                                    Message    = ex.InnerException.Message,
                                    UserId     = callerId
                                });
                            }

                            return(null);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.BannedService.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.BannedService.Add",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }