Beispiel #1
0
        public List <Entry> GetEntry(Expression <Func <Entry, bool> > whereClause)
        {
            try
            {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.TranslationEntries
                               .AsNoTracking()
                               .Include(x => x.Language)
                               .ToList());
                    }

                    return(ubc.TranslationEntries
                           .AsNoTracking()
                           .Where(whereClause)
                           .Include(x => x.Language)
                           .ToList());
                }
            }
            catch
            {
                return(new List <Entry>());
            }
        }
 public List <SupportSessionLog> Add(List <SupportSessionLog> supportSessionLog, int callerId)
 {
     using (UBContext ubc = new UBContext())
     {
         try
         {
             ubc.Add(supportSessionLog);
             ubc.SaveChanges();
             return(supportSessionLog);
         }
         catch (Exception ex)
         {
             if (ex.InnerException != null)
             {
                 Utils.Logging.AddLog(new SystemLog()
                 {
                     LoggerName = "Unifiedban.Data",
                     Date       = DateTime.Now,
                     Function   = "Unifiedban.Data.SupportSessionLogService.Add",
                     Level      = SystemLog.Levels.Warn,
                     Message    = ex.InnerException.Message,
                     UserId     = callerId
                 });
             }
         }
         return(null);
     }
 }
Beispiel #3
0
        public Button Update(Button button, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                Button exists = ubc.Buttons
                                .Where(x => x.ButtonId == button.ButtonId)
                                .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.Name    = button.Name;
                    exists.Content = button.Content;
                    exists.Scope   = button.Scope;
                    exists.GroupId = button.GroupId;

                    ubc.SaveChanges();
                    return(button);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.ButtonService.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.ButtonService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Beispiel #4
0
        public Language UpdateLanguage(Language language, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                Language exists = ubc.Languages
                                  .Where(x => x.LanguageId == language.LanguageId)
                                  .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.Name          = language.Name;
                    exists.UniversalCode = language.UniversalCode;
                    exists.Status        = language.Status;

                    ubc.SaveChanges();
                    return(language);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.LanguageService.UpdateLanguage",
                        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.LanguageService.UpdateLanguage",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Beispiel #5
0
        public Operator Update(Operator oper, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                Operator exists = ubc.Operators
                                  .Where(x => x.OperatorId == oper.OperatorId)
                                  .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.TelegramUserId = oper.TelegramUserId;
                    exists.Level          = oper.Level;

                    ubc.SaveChanges();
                    return(oper);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.OperatorService.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.OperatorService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Beispiel #6
0
        public Entry UpdateEntry(Entry entry, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                Entry exists = ubc.TranslationEntries
                               .Where(x => x.KeyId == entry.KeyId)
                               .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.LanguageId  = entry.LanguageId;
                    exists.Translation = entry.Translation;

                    ubc.SaveChanges();
                    return(entry);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.LanguageService.UpdateEntry",
                        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.LanguageService.UpdateEntry",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Beispiel #7
0
        public SystemLog.ErrorCodes Remove(DashboardSession dashboardSession, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                DashboardSession exists = ubc.DashboardSessions
                                          .Where(x => x.DashboardSessionId == dashboardSession.DashboardSessionId &&
                                                 x.DashboardUserId == dashboardSession.DashboardUserId &&
                                                 x.DeviceId == dashboardSession.DeviceId)
                                          .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.DashboardSessionService.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.DashboardSessionService.Remove",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(SystemLog.ErrorCodes.Error);
            }
        }
Beispiel #8
0
        public SysConfig Update(SysConfig sysConfig, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                SysConfig exists = ubc.SysConfigs
                                   .Where(x => x.SysConfigId == sysConfig.SysConfigId)
                                   .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.Value = sysConfig.Value;

                    ubc.SaveChanges();
                    return(sysConfig);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.SysConfigService.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.SysConfigService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Beispiel #9
0
        public ActionType Update(ActionType actionType, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                ActionType exists = ubc.ActionTypes
                                    .Where(x => x.ActionTypeId == actionType.ActionTypeId)
                                    .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.Name = actionType.Name;
                    ubc.SaveChanges();
                    return(actionType);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.ActionTypeService.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.ActionTypeService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Beispiel #10
0
        public SystemLog.ErrorCodes RemoveKey(Key key, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                Key exists = ubc.TranslationKeys
                             .Where(x => x.KeyId == key.KeyId)
                             .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.LanguageService.RemoveKey",
                        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.LanguageService.RemoveKey",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(SystemLog.ErrorCodes.Error);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Creates a new DashboardSession
        /// </summary>
        /// <param name="dashboardSession"></param>
        /// <param name="callerId"></param>
        /// <returns>DashboardSession or Response</returns>
        public object Add(DashboardSession dashboardSession, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                try
                {
                    ubc.Add(dashboardSession);
                    ubc.SaveChanges();

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

                return(new Response()
                {
                    StatusCode = 4006,
                    StatusDescription = "Error creating DashboardSession on database."
                });
            }
        }
Beispiel #12
0
 public List <TrustFactorLog> Add(List <TrustFactorLog> trustFactorLog, int callerId)
 {
     using (UBContext ubc = new UBContext())
     {
         try
         {
             foreach (var log in trustFactorLog)
             {
                 ubc.Add(log);
             }
             ubc.SaveChanges();
             return(trustFactorLog);
         }
         catch (Exception ex)
         {
             Utils.Logging.AddLog(new SystemLog()
             {
                 LoggerName = "Unifiedban",
                 Date       = DateTime.Now,
                 Function   = "Unifiedban.Data.TrustFactorLogService.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.TrustFactorLogService.Add",
                     Level      = SystemLog.Levels.Warn,
                     Message    = ex.InnerException.Message,
                     UserId     = callerId
                 });
             }
         }
         return(null);
     }
 }
Beispiel #13
0
        public List <ActionType> Get(Expression <Func <ActionType, bool> > whereClause)
        {
            try {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.ActionTypes
                               .AsNoTracking()
                               .ToList());
                    }

                    return(ubc.ActionTypes
                           .AsNoTracking()
                           .Where(whereClause)
                           .ToList());
                }
            }
            catch
            {
                return(new List <ActionType>());
            }
        }
Beispiel #14
0
 public Operator Add(Operator oper, int callerId)
 {
     using (UBContext ubc = new UBContext())
     {
         try
         {
             ubc.Add(oper);
             ubc.SaveChanges();
             return(oper);
         }
         catch (Exception ex)
         {
             Utils.Logging.AddLog(new SystemLog()
             {
                 LoggerName = "Unifiedban",
                 Date       = DateTime.Now,
                 Function   = "Unifiedban.Data.OperatorService.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.OperatorService.Add",
                     Level      = SystemLog.Levels.Warn,
                     Message    = ex.InnerException.Message,
                     UserId     = callerId
                 });
             }
         }
         return(null);
     }
 }
Beispiel #15
0
        public List <OperationLog> Get(Expression <Func <OperationLog, bool> > whereClause)
        {
            try
            {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.OperationLogs
                               .AsNoTracking()
                               .ToList());
                    }

                    return(ubc.OperationLogs
                           .AsNoTracking()
                           .Where(whereClause)
                           .ToList());
                }
            }
            catch
            {
                return(new List <OperationLog>());
            }
        }
Beispiel #16
0
        public List <Key> GetKey(Expression <Func <Key, bool> > whereClause)
        {
            try
            {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.TranslationKeys
                               .AsNoTracking()
                               .ToList());
                    }

                    return(ubc.TranslationKeys
                           .AsNoTracking()
                           .Where(whereClause)
                           .ToList());
                }
            }
            catch
            {
                return(new List <Key>());
            }
        }
Beispiel #17
0
        public List <DashboardSession> Get(Expression <Func <DashboardSession, bool> > whereClause)
        {
            try
            {
                using (UBContext ubc = new UBContext())
                {
                    if (whereClause == null)
                    {
                        return(ubc.DashboardSessions
                               .AsNoTracking()
                               .ToList());
                    }

                    return(ubc.DashboardSessions
                           .AsNoTracking()
                           .Where(whereClause)
                           .ToList());
                }
            }
            catch
            {
                return(new List <DashboardSession>());
            }
        }