public void Visit(UserAccessRights accessRights)
        {
            var rules = ConvertRules(accessRights);
            var dto   = AccessRights.ForUser(accessRights.UserName, rules.Permanent.ToArray(), rules.Scheduled.ToArray());

            UserAccessRightsDto.Add(dto);
        }
        public static UserAccessRules GetUserRights(UserAccessRights accessLevel)
        {
            var rules = new UserAccessRules();

            switch (accessLevel)
            {
            case UserAccessRights.Technician:
                rules.AllowAction(UserActions.InspectDevices);
                rules.AllowAction(UserActions.AddDevice);
                rules.AllowAction(UserActions.RemoveDevice);
                rules.AllowAction(UserActions.InspectCertificates);
                break;

            case UserAccessRights.Administrator:
                rules.AllowAction(UserActions.InspectDevices);
                rules.AllowAction(UserActions.AddDevice);
                rules.AllowAction(UserActions.RemoveDevice);

                rules.AllowAction(UserActions.InspectCertificates);

                rules.AllowAction(UserActions.InspectUsers);
                break;

            case UserAccessRights.Superuser:
                rules.AllowEverything();
                break;
            }

            return(rules);
        }
Example #3
0
        public UserAccessRightsCollec Get(long RoleID)
        {
            UserAccessRightsCollec objCollec = new UserAccessRightsCollec();


            try
            {
                SqlParameter[] paramList = new SqlParameter[] {
                    new SqlParameter("@UserRoleID", RoleID)
                };

                DataTable dt = Execute.RunSP_DataTable(Connection, "SPGET_UserAccessRights_By_USERROLE", paramList);

                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        UserAccessRights obj = new UserAccessRights();

                        obj.MenuID     = Convert.ToString(dt.Rows[i]["Menu_ID"]);
                        obj.MenuName   = Convert.ToString(dt.Rows[i]["Menu_Item"]);
                        obj.Permission = Convert.ToString(dt.Rows[i]["Access_Permission"]);
                        obj.UserRoleID = Convert.ToInt64(dt.Rows[i]["UserRoleID"]);

                        objCollec.Add(obj);
                    }
                }

                return(objCollec);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Example #4
0
        public UserAccessRights Get(String MenuID, long RoleID)
        {
            UserAccessRights obj = new UserAccessRights();

            try
            {
                SqlParameter[] paramList = new SqlParameter[] {
                    new SqlParameter("@Menu_ID", MenuID),
                    new SqlParameter("@UserRoleID", RoleID)
                };

                DataTable dt = Execute.RunSP_DataTable(Connection, "SPGET_UserAccessRights_By_ID", paramList);

                if (dt.Rows.Count > 0)
                {
                    obj.MenuID     = Convert.ToString(dt.Rows[0]["Menu_ID"]);
                    obj.MenuName   = Convert.ToString(dt.Rows[0]["Menu_Item"]);
                    obj.Permission = Convert.ToString(dt.Rows[0]["Access_Permission"]);
                    obj.UserRoleID = Convert.ToInt64(dt.Rows[0]["UserRoleID"]);
                }

                return(obj);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Example #5
0
        public ActionResult ModuleAccess()
        {
            UserAccessRights AccessModel = new UserAccessRights();

            AccessModel.moduleaccess = dbService.GetModuleAccessRights(int.Parse(Membership.GetUser().ProviderUserKey.ToString()));

            return(View("~/Views/Shared/_MainMenu.aspx", AccessModel));
        }
Example #6
0
 public void LoadNode(TreeNode node, UserAccessRights obj)
 {
     if (node.Name == obj.MenuID)
     {
         if (obj.Permission.Equals("Active"))
         {
             node.Checked = true;
         }
         else
         {
             node.Checked = false;
         }
     }
     for (int i = 0; i < node.Nodes.Count; i++)
     {
         LoadNode(node.Nodes[i], obj);
     }
 }
Example #7
0
        public int Add(UserAccessRights obj)
        {
            try
            {
                SqlParameter[] paramList = new SqlParameter[] {
                    new SqlParameter("@Menu_Item", obj.MenuName),
                    new SqlParameter("@Menu_ID", obj.MenuID),
                    new SqlParameter("@UserRoleID", obj.UserRoleID),
                    new SqlParameter("@Access_Permission", obj.Permission)
                };

                return(Execute.RunSP_RowsEffected(Connection, "SPADD_UserAccessRights", paramList));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Example #8
0
        public void SaveNode(TreeNode node)
        {
            UserAccessRights obj = new UserAccessRights();

            obj.MenuID   = node.Name;
            obj.MenuName = node.Text;
            if (node.Checked)
            {
                obj.Permission = "Active";
            }
            else
            {
                obj.Permission = "InActive";
            }
            obj.UserRoleID = objUserRole.UserRoleID;
            objUserAccessRightsDL.Add(obj);

            for (int i = 0; i < node.Nodes.Count; i++)
            {
                SaveNode(node.Nodes[i]);
            }
        }
Example #9
0
        public List <UserAccessRights> GetAccessRights(int employeeID)
        {
            List <UserAccessRights> userAccess = new List <UserAccessRights>();

            using (var db = new FASTDBEntities())
            {
                var rights = from right in db.AccessRights
                             where ((right.EmployeeID == employeeID) && (right.Status == 1))
                             select right;

                foreach (AccessRight right in rights)
                {
                    UserAccessRights access = new UserAccessRights();
                    access.DepartmentID = right.DepartmentID;
                    access.AccessLevel  = right.AccessLevel;

                    userAccess.Add(access);
                }
            }

            return(userAccess);
        }
Example #10
0
        private void LoadControls(Control.ControlCollection Items)
        {
            UserAccessRights_DL objUserAccessRightsDL = new UserAccessRights_DL(ConnectionStringClass.GetConnection());

            try
            {
                foreach (Control var in Items)
                {
                    if (var.GetType().Equals(typeof(Button)))
                    {
                        if ((!var.Name.Equals("btnExit")) && (!var.Name.Equals("btnClose")))
                        {
                            UserAccessRights obj = objUserAccessRightsDL.Get(var.Name, CurrentUser.UserRoleID);
                            if (obj != null)
                            {
                                if (obj.Permission == "Active")
                                {
                                    var.Visible = true;
                                }
                                else
                                {
                                    var.Visible = false;
                                }
                            }
                        }
                    }
                    if (var != null)
                    {
                        LoadControls(var.Controls);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #11
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            //Add the event for catching unhandled exceptions on the thread attached to the specific Dispatcher
            DispatcherUnhandledException += App_DispatcherUnhandledException;

            //Add the event handler for handling non-UI thread exceptions to the event.
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            //Update Settings if new version
            var _settingsUpdated = false;

            if (!Settings.Default.SettingsUpdated)
            {
                Settings.Default.Upgrade();
                Settings.Default.Reload();
                Settings.Default.SettingsUpdated = true;
                Settings.Default.Save();
                _settingsUpdated = true;
            }

            //Set WorkingFolder
            Settings.Default.WorkingFolder =
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "RIS");
            Settings.Default.Save();
            if (!Directory.Exists(Settings.Default.WorkingFolder))
            {
                Directory.CreateDirectory(Settings.Default.WorkingFolder);
            }

            //Check rights on working folder
            try
            {
                var accessRights = new UserAccessRights(Settings.Default.WorkingFolder);
                if (!accessRights.CanModify)
                {
                    MessageBox.Show(
                        $"Kein Zugriff auf den Ordner '{Settings.Default.WorkingFolder}'.\r\nBitte Überpürfen Sie Ihre Berechtigungen.",
                        MessageBoxButton.OK, MessageBoxImage.Error);
                    Current.Shutdown(-1);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteError(MethodBase.GetCurrentMethod(), ex);
                Current.Shutdown(-1);
            }

            //Initialize logger with path
            Path_Log = Path.Combine(Settings.Default.WorkingFolder, "Log");
            Logger.Initialize(Path_Log);
            Logger.WriteDebug(
                $"{Assembly.GetEntryAssembly().GetName().Name} {Assembly.GetExecutingAssembly().GetName().Version} -> start");
            Logger.SetLevel(Settings.Default.LogLevel);
            Logger.WriteDebug("RIS: WorkingFolder -> " + Settings.Default.WorkingFolder);

            //MVVM Light Messenger
            DispatcherHelper.Initialize();

            //Register Locators and Factories
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
            ServiceFactory.Register();
            ViewModelFactory.Register();
            ViewFactory.Register();

            //Show start window
            ViewFactory.StartSplashScreen.Show();

            //Initialize Factories
            ServiceFactory.Initialize();
            ViewModelFactory.Initialize();
            ViewFactory.Initialize();

            //Folder Temp
            Path_Temp = Path.Combine(Settings.Default.WorkingFolder, "Temp");
            if (!Directory.Exists(Path_Temp))
            {
                Directory.CreateDirectory(Path_Temp);
                Logger.WriteDebug("RIS: Ordner für Temp-Files wurde erstellt -> " + Path_Temp);
            }

            foreach (var _tempFile in new DirectoryInfo(Path_Temp).GetFiles())
            {
                _tempFile.Delete();
                Logger.WriteDebug("RIS: Delete -> " + _tempFile);
            }

            //Folder Funkaufzeichnung
            Path_Record = Path.Combine(Settings.Default.WorkingFolder, "Record");
            if (!Directory.Exists(Path_Record))
            {
                Directory.CreateDirectory(Path_Record);
                Logger.WriteDebug("RIS: Ordner für Funkaufzeichnung wurde erstellt -> " + Path_Record);
            }

            //Delete old data on update
            if (_settingsUpdated)
            {
                //Delete all old data
                if (File.Exists(Path_DataVehicles))
                {
                    File.Delete(Path_DataVehicles);
                    Logger.WriteDebug("RIS: Delete -> " + Path_DataVehicles);
                }

                if (File.Exists(Path_DataAlarms))
                {
                    File.Delete(Path_DataAlarms);
                    Logger.WriteDebug("RIS: Delete -> " + Path_DataAlarms);
                }

                foreach (var _logFile in new DirectoryInfo(Path_Log).GetFiles())
                {
                    try
                    {
                        _logFile.Delete();
                        Logger.WriteDebug("RIS: Delete -> " + _logFile);
                    }
                    catch (IOException ex)
                    {
                        Logger.WriteError(MethodBase.GetCurrentMethod(), ex);
                    }
                }
            }

            //Start all services
            ServiceFactory.Start();

            //Show Window
            MainWindow = new MainWindow();
            MainWindow.Show();

            //Close StartScreen
            ViewFactory.StartSplashScreen.Close();
        }
Example #12
0
 public int Update(UserAccessRights obj)
 {
     return(0);
 }