Exemplo n.º 1
0
        public Response <ListRegisteredUsers[]> listRegisteredUser([FromBody] FilterRegisteredUser request)
        {
            string userlogin = string.Empty;
            string token     = Request.Headers["Authorization"];

            // Get user login from token
            var info = this._authService.checkToken(token);
            Response <ListRegisteredUsers[]> response = new Response <ListRegisteredUsers[]>();

            if (!string.IsNullOrEmpty(info.Username))
            {
                return(this._authService.listRegisteredUser(request));
            }
            else
            {
                response.message      = "Unauthorize";
                response.message_type = 2;
            }
            return(response);
        }
Exemplo n.º 2
0
        public Response <ListRegisteredUsers[]> listRegisteredUser(FilterRegisteredUser request)
        {
            Response <ListRegisteredUsers[]> response = new Response <ListRegisteredUsers[]> {
            };


            var query = from x in this.Db.Users
                        from y in this.Db.UserRoles
                        from w in this.Db.Roles
                        where x.Id == y.UserId && w.Id == y.RoleId
                        select new ListRegisteredUsers {
                Email          = x.Email,
                FullName       = x.FullName,
                Phone          = x.PhoneNumber,
                UserName       = x.UserName,
                ProfilePicture = "staticFiles/" + x.ProfilePicture,
                Role           = w.Name
            };

            if (!string.IsNullOrEmpty(request.Role))
            {
                query = query.Where(a => a.Role == request.Role);
            }



            // Paging
            var count = query.Count();
            var items = query.Skip((request.pageIndex - 1) * request.pageSize).Take(request.pageSize).ToArray();

            response.data = items;

            // Property Information for javascript client
            response.count      = count;
            response.totalpages = (int)Math.Ceiling(count / (double)request.pageSize);
            response.totalpages = response.totalpages < 0 ? 1 : response.totalpages;

            return(response);
        }