/// <summary>
        /// Obtiene un usuario de la base de datos por su id
        /// </summary>
        /// <param name="id">Id del usuario que se desea buscar</param>
        /// <returns>El usuario que corresponde con el id</returns>
        /// <exception cref="UserNotFoundException">En caso de no encontrar ningun usuario se devuelve
        /// una excepcion para avisar que no se encontró ningún usuario con ese id</exception>
        public User GetUserById(int id)
        {
            try
            {
                //    _logger.LogInformation("Entrando en GetUserById(id)",id);
                User       user;
                DAOFactory factory = DAOFactory.GetFactory(DAOFactory.Type.Postgres);
                RoleDAO    roles   = factory.GetRoleDAO();
                var        table   = PgConnection.Instance.ExecuteFunction(SP_GETUSERBYID, id);
                if (table.Rows.Count == 0)
                {
                    throw new UserNotFoundException("No se Encontró Usuario");
                }

                var user_id    = Convert.ToInt32(table.Rows[0][0]);
                var documentId = Convert.ToInt64(table.Rows[0][1]);
                var name       = table.Rows[0][2].ToString();
                var lastname   = table.Rows[0][3].ToString();
                var email      = table.Rows[0][4].ToString();
                user = new User(user_id, documentId, name, lastname, email);

                user.Roles = roles.GetRolesForUser(id);
                //    _logger.LogDebug("User:"******"Error", e);
                e.ToString();
                throw;
            }
        }
Exemplo n.º 2
0
 public bool GetByNome(string nome, Connection conn, MySqlTransaction transaction = null)
 {
     using (var dao = new RoleDAO(conn))
     {
         return(dao.GetByNome(this, nome, transaction));
     }
 }
Exemplo n.º 3
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            CommonFunc cFunc = new CommonFunc();

            if (cFunc.GetSession() == null)
            {
                return(false);                                               //Chua dang nhap
            }
            else if (cFunc.CheckSessionInvalid() == false)
            {
                return(false);                                             //Ko dung phien
            }
            else                                                           //check role
            {
                RoleDAO     roleDao   = new RoleDAO();
                List <ROLE> userRoles = roleDao.GetRoles(cFunc.GetIdUserBySession());

                foreach (var role in allowedRoles)
                {
                    foreach (ROLE uR in userRoles)
                    {
                        if (role == uR.ROLE1)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
        }
Exemplo n.º 4
0
 public ViewRoles(controlPanel parent)
 {
     InitializeComponent();
     this.parent          = parent;
     dataGrid.IsReadOnly  = true;
     dataGrid.ItemsSource = RoleDAO.getAllRoles();
 }
Exemplo n.º 5
0
 public static Role FindByNormalizedName(string normalizedName, Connection connection, MySqlTransaction transaction = null)
 {
     using (var dao = new RoleDAO(connection))
     {
         return(dao.FindByNormalizedName(normalizedName.ToUpper(), transaction));
     }
 }
Exemplo n.º 6
0
 public static Role FindByName(string name, Connection connection, MySqlTransaction transaction = null)
 {
     using (var dao = new RoleDAO(connection))
     {
         return(dao.FindByName(name, transaction));
     }
 }
Exemplo n.º 7
0
 public void Delete(Connection connection, MySqlTransaction transaction = null)
 {
     using (var dao = new RoleDAO(connection))
     {
         dao.Remove(this, transaction);
     }
 }
Exemplo n.º 8
0
 public static IList <RoleModel> GetRoles(Connection conn, MySqlTransaction transaction)
 {
     using (var dao = new RoleDAO(conn))
     {
         return(dao.GetRoles(transaction));
     }
 }
Exemplo n.º 9
0
        // GET: Admin/QuyenHanThanhVien
        public ActionResult Index(string searchString, int page = 1, int pagesize = 5)
        {
            var dao  = new RoleDAO();
            var list = dao.ListAll(searchString, page, pagesize);

            return(View(list));
        }
Exemplo n.º 10
0
 public static void Init()
 {
     _apis        = RoleDAO.GetApis().ToList();
     _headings    = RoleDAO.GetHeadings().ToList();
     _subHeadings = RoleDAO.GetSubHeadings().ToList();
     _roles       = RoleDAO.GetRoles().ToList();
 }
Exemplo n.º 11
0
 public HomeController()
 {
     _categoryDAO            = new CategoryDAO();
     _employeeDAO            = new EmployeeDAO();
     _roleDAO                = new RoleDAO();
     _notificationChannelDAO = new NotificationChannelDAO();
 }
Exemplo n.º 12
0
        //hien thi danh sach user
        public ActionResult Users()
        {
            if (CheckStatusUser())
            {
                return(RedirectToAction("Login"));
            }

            if (CheckAdmin())
            {
                int page = Convert.ToInt32(Request["page"]);

                if (page <= 0)
                {
                    page = 1;
                }

                UserDAO       userDao       = new UserDAO();
                RoleDAO       roleDao       = new RoleDAO();
                StatusUserDAO statusUserDao = new StatusUserDAO();

                var list = userDao.Users(new Pagination(10, page));

                ViewBag.Users       = list.Comics;
                ViewBag.Page        = list.Page;
                ViewBag.Numpage     = list.PageSize;
                ViewBag.Roles       = roleDao.List();
                ViewBag.StatusUsers = statusUserDao.List();

                return(View());
            }

            return(RedirectToAction("Index"));
        }
        // private readonly ILogger _logger;


        // GETS
        /// <summary>
        ///  Se conecta con la base de datos para seleccionar todos los usuarios que no sean clientes
        /// </summary>
        /// <returns>Una lista de usuarios que no tienen como rol cliente</returns>
        public List <User> GetEmployees()
        {
            try
            {
                // _logger.LogInformation("Entrando en GetEmployees");
                var        users   = new List <User>();
                var        table   = PgConnection.Instance.ExecuteFunction(SP_GETEMPLOYEES);
                DAOFactory factory = DAOFactory.GetFactory(DAOFactory.Type.Postgres);
                RoleDAO    roles   = factory.GetRoleDAO();
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    var id         = Convert.ToInt32(table.Rows[i][0]);
                    var documentId = Convert.ToInt64(table.Rows[i][1]);
                    var name       = table.Rows[i][2].ToString();
                    var lastname   = table.Rows[i][3].ToString();
                    var email      = table.Rows[i][4].ToString();
                    var user       = new User(id, documentId, name, lastname, email);

                    //Role roles = new List<Entity>();

                    user.Roles = roles.GetRolesForUser(id);
                    users.Add(user);
                }
                //    _logger.LogDebug("Users:", users);
                return(users);
            }
            catch (Exception e) {
                //  _logger.LogError("Error", e);
                e.ToString();
                throw;
            }
        }
Exemplo n.º 14
0
 public static Role FindById(int id, Connection connection, MySqlTransaction transaction = null)
 {
     using (var dao = new RoleDAO(connection))
     {
         return(dao.FindById(id, transaction));
     }
 }
Exemplo n.º 15
0
 public static List <Role> FindRoles(Connection connection, MySqlTransaction transaction)
 {
     using (var dao = new RoleDAO(connection))
     {
         return(dao.FindRoles(transaction));
     }
 }
Exemplo n.º 16
0
 public bool GetById(int id, Connection conn, MySqlTransaction transaction = null)
 {
     using (var dao = new RoleDAO(conn))
     {
         return(dao.GetById(this, id, transaction));
     }
 }
Exemplo n.º 17
0
        public Status delete(List <int> roleIDs)
        {
            if (roleIDs.Count == 0)
            {
                return(Status.SUCCESS);
            }

            RoleDAO roleDao = Factory.getInstance <RoleDAO>();

            Role_PermissionDAO          role_PermissionDao = Factory.getInstance <Role_PermissionDAO>();
            Dictionary <string, object> wherelist          = new Dictionary <string, object>();

            foreach (int roleID in roleIDs)
            {
                //获取角色信息
                RoleVO roleVo = roleDao.getOne <RoleVO>(roleID);
                if (roleVo.isIntegrant)//禁止删除系统角色
                {
                    return(Status.PERMISSION_DENIED);
                }
                wherelist.Clear();
                wherelist.Add("roleID", roleID);
                role_PermissionDao.delete(wherelist);
            }

            return(Status.SUCCESS);
        }
Exemplo n.º 18
0
        public ActionResult Login(FormCollection f)
        {
            string email    = f["email"].ToString();
            string password = f["password"].ToString();

            UserDAO userDao = new UserDAO();
            var     res     = userDao.Login(email, GetMD5(password));

            if (res)
            {
                var user     = userDao.GetUser(email);
                var roleDao  = new RoleDAO();
                var listRole = roleDao.GetRoles(user.ID);

                CommonFunc cFunc = new CommonFunc();
                cFunc.SetSession(user.ID, "20211");
                cFunc.SetCookie();


                if (listRole.Where(r => r.ROLE1 == "ADMIN").FirstOrDefault() != null)
                {
                    return(Content("/Admin/Home/Index/" + user.ID));
                }
                else if (listRole.Where(r => r.ROLE1 == "TEACHER").FirstOrDefault() != null)
                {
                    return(Content("/Teacher/Home/Index/" + user.ID));
                }
                else if (listRole.Where(r => r.ROLE1 == "STUDENT").FirstOrDefault() != null)
                {
                    return(Content("/Student/Home/Index/" + user.ID));
                }
                //}
            }
            return(Content("false"));
        }
Exemplo n.º 19
0
        public void deleteRoleById()
        {
            int id = RoleDAO.add(testStr);

            RoleDAO.deleteById(id);
            Assert.Null(RoleDAO.getById(id));
        }
Exemplo n.º 20
0
        private void cmb_rol_SelectedIndexChanged(object sender, EventArgs e)
        {
            RoleDAO role = new RoleDAO();

            role = (RoleDAO)cmb_rol.SelectedItem;

            this.openContainer(role.Id);
        }
Exemplo n.º 21
0
        public void register(UserDto user)
        {
            Users newUser = new Users();

            newUser.CreatedDate = DateTime.Now;
            newUser.Role        = RoleDAO.getRoleById(CONST.ROLE.NORMALUSER);
            newUser.Status      = null;
        }
Exemplo n.º 22
0
        public void Delete(City city)
        {
            RoleDAO roleDAO = new RoleDAO();

            city.Active = 0;

            roleDAO.Update(TABLE, IDFIELDNAME, city.AssembleDictionary(), city.Id);
        }
Exemplo n.º 23
0
        public void getRoleById()
        {
            Role test = RoleDAO.getById(testId);

            Assert.NotNull(test);
            Assert.AreEqual(test.Id, testId);
            Assert.AreEqual(test.Name, testStr);
        }
Exemplo n.º 24
0
        public void SetViewBag()
        {
            var _useraccess = new UserStatusDAO();
            var _userrole   = new RoleDAO();

            ViewBag.UserRole   = _userrole.ListRole();
            ViewBag.UserStatus = _useraccess.ListUserStatus();
        }
Exemplo n.º 25
0
 public SimuladorPermissoesController(PermissoesDaSimulacaoDAO permiDAO,
                                      RoleDAO roleDAO,
                                      TipoDeCalculosDAO tipoCalc)
 {
     this.permissaoDAO  = permiDAO;
     this.roleDAO       = roleDAO;
     this.tipoDeCalculo = tipoCalc;
 }
Exemplo n.º 26
0
        public void Delete(Role role)
        {
            RoleDAO roleDAO = new RoleDAO();

            role.Active = 0;

            roleDAO.Update(TABLE, IDFIELDNAME, role.AssembleDictionary(), role.Id);
        }
        // GET: Admin/Role
        public ActionResult Index(string searchString, int page = 1, int pageSize = 10)
        {
            var dao   = new RoleDAO();
            var model = dao.ListAllPaging(searchString, page, pageSize);

            ViewBag.SearchString = searchString;
            return(View(model));
        }
Exemplo n.º 28
0
        public RoleDAO Map(Role _roletomap)
        {
            RoleDAO _roletoview = new RoleDAO();

            _roletoview.RoleID   = _roletomap.RoleID;
            _roletoview.RoleName = _roletomap.RoleName;
            _roletoview.RoleDesc = _roletomap.RoleName;
            return(_roletoview);
        }
Exemplo n.º 29
0
 public SystemService(IMapper mapper, ConfigurationOptions options)
 {
     _menuDao          = new MenuDAO(options);
     _permissionDao    = new PermissionDAO(options);
     _permissionApiDao = new PermissionApiDAO(options);
     _userDao          = new UserDAO(options);
     _roleDao          = new RoleDAO(options);
     _mapper           = mapper;
 }
Exemplo n.º 30
0
 public override string[] GetAllRoles()
 {
     IList<Role> role = new RoleDAO().GetAll();
     string[] rs = new string[role.Count];
     for (int i = 0; i < rs.Length; i++)
     {
         rs[i] = role[i].RoleName;
     }
     return rs;
 }
Exemplo n.º 31
0
 public static void Main()
 {
     IUserDAO udao     = new UserDAO();
     IRoleDAO rdao     = new RoleDAO();
     string   username = "******";
     string   roleid   = "Rep";
     User     u        = udao.GetUserByUsername(username);
     Role     r        = rdao.GetRoleInfo(roleid);
     //udao.UpdateUserRole(u,r);
 }
Exemplo n.º 32
0
 public override string[] GetRolesForUser(string username)
 {
     RoleDAO rd = new RoleDAO();
     IList<Role> role = rd.GetByUserName(username); 
     string[] rs = new string[role.Count];
     for(int i=0;i<rs.Length;i++)
     {
         rs[i] = role[i].RoleName;
     }
     return rs;
 }
Exemplo n.º 33
0
 public override bool IsUserInRole(string username, string roleName)
 {
     RoleDAO rd = new RoleDAO();
     IList<Role> roles = rd.GetByUserName(username);
     foreach (Role r in roles)
     {
         if (r.RoleName == roleName)
             return true;
     }
     return false;
 }
Exemplo n.º 34
0
        public static void LoadCurrentUser(string userName, HttpContext context)
        {
            User User = (new UserDAO()).GetByUserName(userName, null);
            Kingdom kingdom = new KingdomDAO().GetByUserId(User.UserId);

            context.Session.Add("KingdomId", kingdom.KingdomId);
            context.Session.Add("CurrentUser", User);
            context.Session.Add("UserId", User.UserId);

            IList<Role> roles = new RoleDAO().GetByUserId(User.UserId);

            Dictionary<string, int> roleNames = new Dictionary<string, int>();
            foreach (Role role in roles)
            {
                if (roleNames.ContainsKey(role.RoleName.ToLower()) == false)
                {
                    roleNames.Add(role.RoleName.ToLower(), role.RoleId);
                }
            }
            context.Session.Add("UserRoles", roleNames);
        }