コード例 #1
0
ファイル: ModuleModel.cs プロジェクト: thobzabuyi/cyca
        public Module EditModule(int moduleId, string description, string baseUrl)
        {
            Module editModule;

            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                editModule = (from m in dbContext.Modules
                              where m.Module_Id.Equals(moduleId)
                              select m).FirstOrDefault();

                if (editModule == null)
                {
                    return(null);
                }

                editModule.Description = description;
                editModule.Base_URL    = baseUrl;

                dbContext.SaveChanges();
            }
            catch (Exception)
            {
                editModule = null;
            }

            return(editModule);
        }
コード例 #2
0
ファイル: ModuleModel.cs プロジェクト: thobzabuyi/cyca
        public Module SetModuleIsDeleted(int moduleId, bool isDeleted)
        {
            Module editModule;

            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                editModule = (from m in dbContext.Modules
                              where m.Module_Id.Equals(moduleId)
                              select m).FirstOrDefault();

                if (editModule == null)
                {
                    return(null);
                }

                editModule.Is_Deleted = isDeleted;

                dbContext.SaveChanges();
            }
            catch (Exception)
            {
                editModule = null;
            }

            return(editModule);
        }
コード例 #3
0
ファイル: MenuModel.cs プロジェクト: thobzabuyi/cyca
        public Menu EditMenu(int menuId, string description)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var editMenu = (from m in dbContext.Menus
                                where m.Menu_Id.Equals(menuId)
                                select m).FirstOrDefault();

                if (editMenu == null)
                {
                    return(null);
                }

                editMenu.Description = description;

                dbContext.SaveChanges();

                return(editMenu);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #4
0
        public User RemoveUserFromRole(int agentId, int roleId)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var roleToRemove = dbContext.Roles.FirstOrDefault(x => x.Role_Id.Equals(roleId));
                if (roleToRemove == null)
                {
                    return(null);
                }

                var userToEdit = dbContext.Users.FirstOrDefault(x => x.User_Id.Equals(agentId));
                if (userToEdit == null)
                {
                    return(null);
                }

                userToEdit.Roles.Remove(roleToRemove);

                dbContext.SaveChanges();

                return(userToEdit);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #5
0
ファイル: MenuModel.cs プロジェクト: thobzabuyi/cyca
        public Menu SetMenuIsDeleted(int menuId, bool isDeleted)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var editMenu = (from m in dbContext.Menus
                                where m.Menu_Id.Equals(menuId)
                                select m).FirstOrDefault();

                if (editMenu == null)
                {
                    return(null);
                }

                editMenu.Is_Deleted = isDeleted;

                dbContext.SaveChanges();

                return(editMenu);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #6
0
ファイル: EmployeeModel.cs プロジェクト: thobzabuyi/cyca
        public Employee SetEmployeeIsDeleted(int employeeId, bool isDeleted)
        {
            Employee editEmployee;

            using (var dbContext = new SDIIS_DatabaseEntities())
            {
                try
                {
                    editEmployee = (from e in dbContext.Employees
                                    where e.Employee_Id.Equals(employeeId)
                                    select e).FirstOrDefault();

                    if (editEmployee == null)
                    {
                        return(null);
                    }

                    editEmployee.Is_Deleted      = isDeleted;
                    editEmployee.User.Is_Deleted = isDeleted;

                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            return(editEmployee);
        }
コード例 #7
0
ファイル: GroupModel.cs プロジェクト: thobzabuyi/cyca
        public Group SetGroupIsDeleted(int groupId, bool isDeleted)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var editGroup = (from g in dbContext.Groups
                                 where g.Group_Id.Equals(groupId)
                                 select g).FirstOrDefault();

                if (editGroup == null)
                {
                    return(null);
                }

                editGroup.Is_Deleted = isDeleted;

                dbContext.SaveChanges();

                return(editGroup);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #8
0
ファイル: GroupModel.cs プロジェクト: thobzabuyi/cyca
        public Group RemoveMenuItemFromRole(int groupId, int roleId)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var roleToRemove = dbContext.Roles.FirstOrDefault(x => x.Role_Id.Equals(roleId));
                if (roleToRemove == null)
                {
                    return(null);
                }

                var groupToEdit = dbContext.Groups.FirstOrDefault(x => x.Group_Id.Equals(groupId));
                if (groupToEdit == null)
                {
                    return(null);
                }

                groupToEdit.Roles.Remove(roleToRemove);

                dbContext.SaveChanges();

                return(groupToEdit);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #9
0
        public User AddUserToRole(int agentId, List <int> roleIds)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var userToEdit = dbContext.Users.FirstOrDefault(x => x.User_Id.Equals(agentId));
                if (userToEdit == null)
                {
                    return(null);
                }

                userToEdit.Roles.Clear();

                foreach (var roleId in roleIds)
                {
                    var roleToAdd = dbContext.Roles.FirstOrDefault(x => x.Role_Id.Equals(roleId));
                    if (roleToAdd == null)
                    {
                        return(null);
                    }

                    userToEdit.Roles.Add(roleToAdd);
                }

                dbContext.SaveChanges();

                return(userToEdit);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #10
0
ファイル: ModuleActionModel.cs プロジェクト: thobzabuyi/cyca
        public Module_Action EditModuleAction(int moduleActionId, int moduleControllerId, string moduleActionName)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var editModuleAction = (from ma in dbContext.Module_Actions
                                        where ma.Module_Action_Id.Equals(moduleActionId)
                                        select ma).FirstOrDefault();

                if (editModuleAction == null)
                {
                    return(null);
                }

                editModuleAction.Module_Controller_Id = moduleControllerId;
                editModuleAction.Module_Action_Name   = moduleActionName;

                dbContext.SaveChanges();

                return(editModuleAction);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #11
0
        public User RemoveUserFromGroup(int agentId, int groupId)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var groupToRemove = dbContext.Groups.FirstOrDefault(x => x.Group_Id.Equals(groupId));
                if (groupToRemove == null)
                {
                    return(null);
                }

                var userToEdit = dbContext.Users.FirstOrDefault(x => x.User_Id.Equals(agentId));
                if (userToEdit == null)
                {
                    return(null);
                }

                userToEdit.Groups.Remove(groupToRemove);

                dbContext.SaveChanges();

                return(userToEdit);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #12
0
ファイル: ModuleActionModel.cs プロジェクト: thobzabuyi/cyca
        public Module_Action AddModuleActionToRole(int moduleActionId, List <int> roleIds)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var moduleActionToEdit = dbContext.Module_Actions.FirstOrDefault(x => x.Module_Action_Id.Equals(moduleActionId));
                if (moduleActionToEdit == null)
                {
                    return(null);
                }

                moduleActionToEdit.Roles.Clear();

                foreach (var roleId in roleIds)
                {
                    var roleToAdd = dbContext.Roles.FirstOrDefault(x => x.Role_Id.Equals(roleId));
                    if (roleToAdd == null)
                    {
                        return(null);
                    }

                    moduleActionToEdit.Roles.Add(roleToAdd);
                }

                dbContext.SaveChanges();

                return(moduleActionToEdit);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #13
0
ファイル: ModuleActionModel.cs プロジェクト: thobzabuyi/cyca
        public Module_Action RemoveMenuItemFromRole(int moduleActionId, int roleId)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var roleToRemove = dbContext.Roles.FirstOrDefault(x => x.Role_Id.Equals(roleId));
                if (roleToRemove == null)
                {
                    return(null);
                }

                var moduleActionToEdit = dbContext.Module_Actions.FirstOrDefault(x => x.Module_Action_Id.Equals(moduleActionId));
                if (moduleActionToEdit == null)
                {
                    return(null);
                }

                moduleActionToEdit.Roles.Remove(roleToRemove);

                dbContext.SaveChanges();

                return(moduleActionToEdit);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #14
0
        public User CreateUser(string firstName, string lastName, bool isActive)
        {
            User newUser;

            using (var dbContext = new SDIIS_DatabaseEntities())
            {
                // TODO: Generate unique username
                // TODO: Generate password

                var user = new User
                {
                    User_Name    = string.Format("{0}{1}", firstName.Substring(0, 1), lastName),
                    Password     = "******",
                    First_Name   = firstName,
                    Last_Name    = lastName,
                    Is_Active    = isActive,
                    Is_Deleted   = false,
                    Date_Created = DateTime.Now,
                };

                try
                {
                    newUser = dbContext.Users.Add(user);
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(null);
                }
            }

            return(newUser);
        }
コード例 #15
0
        public Module_Controller EditModuleController(int moduleControllerId, int moduleId, string moduleControllerName)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var editModuleController = (from mc in dbContext.Module_Controllers
                                            where mc.Module_Controller_Id.Equals(moduleControllerId)
                                            select mc).FirstOrDefault();

                if (editModuleController == null)
                {
                    return(null);
                }

                editModuleController.Module_Controller_Id   = moduleControllerId;
                editModuleController.Module_Controller_Name = moduleControllerName;

                dbContext.SaveChanges();

                return(editModuleController);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #16
0
ファイル: GroupModel.cs プロジェクト: thobzabuyi/cyca
        public Group AddGroupToRole(int groupId, List <int> roleIds)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var groupToEdit = dbContext.Groups.FirstOrDefault(x => x.Group_Id.Equals(groupId));
                if (groupToEdit == null)
                {
                    return(null);
                }

                groupToEdit.Roles.Clear();

                foreach (var roleId in roleIds)
                {
                    var roleToAdd = dbContext.Roles.FirstOrDefault(x => x.Role_Id.Equals(roleId));
                    if (roleToAdd == null)
                    {
                        return(null);
                    }

                    groupToEdit.Roles.Add(roleToAdd);
                }

                dbContext.SaveChanges();

                return(groupToEdit);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #17
0
        public User SetUserIsDeleted(int userId, bool isDeleted)
        {
            User editUser;

            using (var dbContext = new SDIIS_DatabaseEntities())
            {
                try
                {
                    editUser = (from a in dbContext.Users
                                where a.User_Id.Equals(userId)
                                select a).FirstOrDefault();

                    if (editUser == null)
                    {
                        return(null);
                    }

                    editUser.Is_Deleted = isDeleted;

                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            return(editUser);
        }
コード例 #18
0
        public User AddUserToGroup(int agentId, List <int> groupIds)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var userToEdit = dbContext.Users.FirstOrDefault(x => x.User_Id.Equals(agentId));
                if (userToEdit == null)
                {
                    return(null);
                }

                userToEdit.Groups.Clear();

                foreach (var groupId in groupIds)
                {
                    var groupToAdd = dbContext.Groups.FirstOrDefault(x => x.Group_Id.Equals(groupId));
                    if (groupToAdd == null)
                    {
                        return(null);
                    }

                    userToEdit.Groups.Add(groupToAdd);
                }

                dbContext.SaveChanges();

                return(userToEdit);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #19
0
        public User EditUser(int userId, string firstName, string lastName)
        {
            User editUser;

            using (var dbContext = new SDIIS_DatabaseEntities())
            {
                try
                {
                    editUser = (from a in dbContext.Users
                                where a.User_Id.Equals(userId)
                                select a).FirstOrDefault();

                    if (editUser == null)
                    {
                        return(null);
                    }

                    editUser.First_Name = firstName;
                    editUser.Last_Name  = lastName;

                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            return(editUser);
        }
コード例 #20
0
ファイル: GroupModel.cs プロジェクト: thobzabuyi/cyca
        public Group EditGroup(int groupId, string description)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var editGroup = (from g in dbContext.Groups
                                 where g.Group_Id.Equals(groupId)
                                 select g).FirstOrDefault();

                if (editGroup == null)
                {
                    return(null);
                }

                editGroup.Description = description;

                dbContext.SaveChanges();

                return(editGroup);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #21
0
ファイル: EmployeeModel.cs プロジェクト: thobzabuyi/cyca
        public Employee EditEmployee(int employeeId, string firstName, string lastName, string persalNumber, int?headOfDepartmentId, int?supervisorId, string phoneNumber, string mobilePhoneNumber,
                                     int?genderId, int?raceId, string idNumber, int?jobPositionId, int?payPointId, int?serviceOfficeId, int?salaryLevelId, bool isShiftWorker, bool isCasualWorker,
                                     bool isActive, bool isDeleted, DateTime dateLastModified, string modifiedBy)
        {
            Employee editEmployee;

            using (var dbContext = new SDIIS_DatabaseEntities())
            {
                try
                {
                    editEmployee = (from e in dbContext.Employees
                                    where e.Employee_Id.Equals(employeeId)
                                    select e).FirstOrDefault();

                    if (editEmployee == null)
                    {
                        return(null);
                    }

                    editEmployee.User.First_Name       = firstName;
                    editEmployee.User.Last_Name        = lastName;
                    editEmployee.Persal_Number         = persalNumber;
                    editEmployee.Head_Of_Department_Id = headOfDepartmentId;
                    editEmployee.Supervisor_Id         = supervisorId;
                    editEmployee.Phone_Number          = phoneNumber;
                    editEmployee.Mobile_Phone_Number   = mobilePhoneNumber;
                    editEmployee.Gender_Id             = genderId;
                    editEmployee.Race_Id            = raceId;
                    editEmployee.ID_Number          = idNumber;
                    editEmployee.Job_Position_Id    = jobPositionId;
                    editEmployee.Paypoint_Id        = payPointId;
                    editEmployee.Service_Office_Id  = serviceOfficeId;
                    editEmployee.Salary_Level_Id    = salaryLevelId;
                    editEmployee.Is_Shift_Worker    = isShiftWorker;
                    editEmployee.Is_Casual_Worker   = isCasualWorker;
                    editEmployee.Is_Active          = isActive;
                    editEmployee.Is_Deleted         = isDeleted;
                    editEmployee.Date_Last_Modified = dateLastModified;
                    editEmployee.Modified_By        = modifiedBy;

                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            return(editEmployee);
        }
コード例 #22
0
ファイル: MenuModel.cs プロジェクト: thobzabuyi/cyca
        public Menu CreateMenu(string description, bool isActive)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            var menu = new Menu()
            {
                Description = description, Is_Active = isActive, Is_Deleted = false
            };

            try
            {
                var newMenu = dbContext.Menus.Add(menu);

                dbContext.SaveChanges();

                return(newMenu);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #23
0
ファイル: ModuleActionModel.cs プロジェクト: thobzabuyi/cyca
        public Module_Action CreateModuleAction(int moduleControllerId, string moduleActionName)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            var moduleAction = new Module_Action()
            {
                Module_Controller_Id = moduleControllerId, Module_Action_Name = moduleActionName
            };

            try
            {
                var newModuleAction = dbContext.Module_Actions.Add(moduleAction);

                dbContext.SaveChanges();

                return(newModuleAction);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #24
0
ファイル: GroupModel.cs プロジェクト: thobzabuyi/cyca
        public Group CreateGroup(string description, bool isActive)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            var group = new Group()
            {
                Description = description, Is_Active = isActive, Is_Deleted = false, Date_Created = DateTime.Now
            };

            try
            {
                var newGroup = dbContext.Groups.Add(group);

                dbContext.SaveChanges();

                return(newGroup);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #25
0
ファイル: MenuItemModel.cs プロジェクト: thobzabuyi/cyca
        public Menu_Item CreateMenuItem(int menuId, string menuText, string menuTooltip, int?moduleActionId, int?parentMenuItemId, bool isActive)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            var menuItem = new Menu_Item()
            {
                Menu_Id = menuId, Menu_Text = menuText, Menu_Tooltip = menuTooltip, Module_Action_Id = moduleActionId, Parent_Menu_Item_Id = parentMenuItemId, Is_Active = isActive, Is_Deleted = false, Date_Created = DateTime.Now
            };

            try
            {
                var newMenuItem = dbContext.Menu_Items.Add(menuItem);

                dbContext.SaveChanges();

                return(newMenuItem);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #26
0
        public User ClearUserGroups(int agentId)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var userToEdit = dbContext.Users.FirstOrDefault(x => x.User_Id.Equals(agentId));
                if (userToEdit == null)
                {
                    return(null);
                }

                userToEdit.Groups.Clear();

                dbContext.SaveChanges();

                return(userToEdit);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #27
0
ファイル: GroupModel.cs プロジェクト: thobzabuyi/cyca
        public Group ClearMenuItemRoles(int groupId)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var groupToEdit = dbContext.Groups.FirstOrDefault(x => x.Group_Id.Equals(groupId));
                if (groupToEdit == null)
                {
                    return(null);
                }

                groupToEdit.Roles.Clear();

                dbContext.SaveChanges();

                return(groupToEdit);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #28
0
ファイル: ModuleActionModel.cs プロジェクト: thobzabuyi/cyca
        public Module_Action ClearMenuItemRoles(int moduleActionId)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                var moduleActionToEdit = dbContext.Module_Actions.FirstOrDefault(x => x.Module_Action_Id.Equals(moduleActionId));
                if (moduleActionToEdit == null)
                {
                    return(null);
                }

                moduleActionToEdit.Roles.Clear();

                dbContext.SaveChanges();

                return(moduleActionToEdit);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #29
0
ファイル: ModuleModel.cs プロジェクト: thobzabuyi/cyca
        public Module CreateModule(string description, string baseUrl, bool isActive)
        {
            Module newModule;

            var dbContext = new SDIIS_DatabaseEntities();

            var module = new Module()
            {
                Description = description, Base_URL = baseUrl, Is_Active = isActive, Is_Deleted = false, Date_Created = DateTime.Now
            };

            try
            {
                newModule = dbContext.Modules.Add(module);

                dbContext.SaveChanges();
            }
            catch (Exception)
            {
                newModule = null;
            }

            return(newModule);
        }
コード例 #30
0
ファイル: EmployeeModel.cs プロジェクト: thobzabuyi/cyca
        public Employee CreateEmployee(string firstName, string lastName, string persalNumber, int?headOfDepartmentId, int?supervisorId, string phoneNumber, string mobilePhoneNumber,
                                       int?genderId, int?raceId, string idNumber, int?jobPositionId, int?payPointId, int?serviceOfficeId, int?salaryLevelId, bool isShiftWorker, bool isCasualWorker,
                                       bool isActive, bool isDeleted, DateTime dateCreated, string createdBy)
        {
            Employee newEmployee;

            using (var dbContext = new SDIIS_DatabaseEntities())
            {
                User newUser;

                var user = new User
                {
                    User_Name    = string.Format("{0}{1}", firstName.Substring(0, 1), lastName),
                    Password     = "******",
                    First_Name   = firstName,
                    Last_Name    = lastName,
                    Is_Active    = isActive,
                    Is_Deleted   = isDeleted,
                    Date_Created = dateCreated,
                    Created_By   = createdBy
                };

                try
                {
                    newUser = dbContext.Users.Add(user);
                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(null);
                }

                if (newUser == null)
                {
                    return(null);
                }

                var employee = new Employee
                {
                    User_Id               = newUser.User_Id,
                    Persal_Number         = persalNumber,
                    Head_Of_Department_Id = headOfDepartmentId,
                    Supervisor_Id         = supervisorId,
                    Phone_Number          = phoneNumber,
                    Mobile_Phone_Number   = mobilePhoneNumber,
                    Gender_Id             = genderId,
                    Race_Id               = raceId,
                    ID_Number             = idNumber,
                    Job_Position_Id       = jobPositionId,
                    Paypoint_Id           = payPointId,
                    Service_Office_Id     = serviceOfficeId,
                    Salary_Level_Id       = salaryLevelId,
                    Is_Shift_Worker       = isShiftWorker,
                    Is_Casual_Worker      = isCasualWorker,
                    Is_Active             = isActive,
                    Is_Deleted            = isDeleted,
                    Date_Created          = dateCreated,
                    Created_By            = createdBy
                };

                try
                {
                    newEmployee = dbContext.Employees.Add(employee);
                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            return(newEmployee);
        }