public virtual object User(int userId, [FromServices] IQueryParams param)
 {
     using (var dbConnection = new SysDB())
     {
         var query = from user in dbConnection.SysUser
                     where user.UserID == userId
                     select new
         {
             UserID   = user.UserID,
             UserName = user.UserName,
             Status   = dbConnection.SysStatus
                        .First(status => status.StatusID == user.StatusID)
                        .Description,
             LastName  = user.LastName,
             FirstName = user.FirstName,
             Email     = user.Email,
             Company   = dbConnection.SysCompany
                         .First(company => company.CompanyID == user.CompanyID)
                         .CompanyName,
             CreatedOn = user.CreatedOn,
             Role      = dbConnection.SysRole
                         .First(role => role.RoleID ==
                                (dbConnection.SysUserrole
                                 .First(userRole => userRole.UserID == user.UserID)
                                 .RoleID))
                         .RoleName
         };
         var data = DataHelper.GetData(query, param);
         return(data.Data);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Applies filter and sort from query parameters to query and returns DataReturn object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        //============================================================
        //Revision History
        //Date        Author          Description
        //06/28/2017  TB               Created
        //============================================================
        public static DataReturn GetData <T>(IQueryable <T> query, IQueryParams param)
        {
            DataReturn retVal = new DataReturn();

            //apply filter if there is one
            if (param.Filter != null)
            {
                query = query.Where(BuildWhereFromFilter <T>(param.Filter));
            }

            //get total if needed
            if (param.NeedsTotal)
            {
                retVal.Total = query.Count();
            }

            //apply sort if there is one
            if (param.Sort != null)
            {
                query = query.OrderBy(BuildSortString(param.Sort));
            }

            //apply paging logic if necessary
            if (param.Take > 0)
            {
                retVal.Data = query.Skip(param.Skip).Take(param.Take).Cast <object>().ToList();
            }
            else
            {
                retVal.Data = query.Cast <object>().ToList();
            }

            return(retVal);
        }
Exemplo n.º 3
0
        public void Test1(
            HttpRequest request,
            HttpResponse response,
            IPathParams pathParams,
            string pathParam1,
            int?pathParam2,
            IQueryParams queryParams,
            IFormParams formParams,
            IFormFileParams files,
            IFormFile uplaod,
            [ReadJson]
            JsonObject jsonObject
            )
        {
            Console.WriteLine($"HttpRequest:{request}");
            Console.WriteLine($"HttpResponse:{response}");
            Console.WriteLine($"IPathParams:{pathParams}");
            Console.WriteLine(pathParam1);
            Console.WriteLine(pathParam2);
            Console.WriteLine($"IQueryParams:{queryParams}");
            Console.WriteLine($"IFormParams:{formParams}");
            Console.WriteLine($"IFormFileParams:{files}");
            Console.WriteLine($"IFormFile:{uplaod}");
            Console.WriteLine($"JsonObject:{jsonObject}");

            response.UseCookie("CookieName", "CookieValue");
            response.UseRedirect("/");
        }
        public virtual object Users([FromServices] IQueryParams param)
        {
            using (var dbConnection = new SysDB())
            {
                var query = from user in dbConnection.SysUser
                            select new { UserID    = user.UserID,
                                         UserName  = user.UserName,
                                         StatusID  = user.StatusID,
                                         LastName  = user.LastName,
                                         FirstName = user.FirstName,
                                         Email     = user.Email,

                                         //As Rodrigo said user company has to be separate varchar of user - 07.24.2017
                                         //Company = dbConnection.SysCompany
                                         //               .First(company => company.CompanyID == user.CompanyID)
                                         //                   .CompanyName,

                                         Company   = user.Company,
                                         CreatedOn = user.CreatedOn,
                                         Role      = dbConnection.SysRole
                                                     .First(role => role.RoleID ==
                                                            (dbConnection.SysUserrole
                                                             .First(userRole => userRole.UserID == user.UserID)
                                                             .RoleID))
                                                     .RoleName };
                var data = DataHelper.GetData(query, param);
                return(data.Data);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Executes Get requests to retrieve all items.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="totalCount">Total count.</param>
        /// <param name="getByPageUrl">Get by page URL.</param>
        /// <param name="queryParams">Query parameters.</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="client">REST client.</param>
        /// <returns></returns>
        protected static List <T> GetAll <T>(int totalCount, string getByPageUrl, IQueryParams queryParams = null, int pageSize = DefaultPageSize, IVcRestClient client = null) where T : IResourceEntity
        {
            int      count    = totalCount;
            int      page     = 1;
            List <T> entities = new List <T>();

            while (count > 0)
            {
                if (queryParams == null)
                {
                    queryParams = new PagingQueryParams(page, pageSize);
                }
                else
                {
                    ((IPagingQueryParams)queryParams).Page     = page;
                    ((IPagingQueryParams)queryParams).PageSize = pageSize;
                }

                entities.AddRange(Get <T>(getByPageUrl, queryParams, client: client));
                page++;
                count -= pageSize;
            }

            return(entities);
        }
Exemplo n.º 6
0
 /// <summary>
 /// this class models a request that can be sent to a service
 /// </summary>
 /// <param name="headers">the headers that should be sent as part of the request</param>
 /// <param name="httpMethod">the httpMethod of the request</param>
 /// <param name="pathParameters">any path parameters required</param>
 /// <param name="queryParameters">any query parameters required</param>
 /// <param name="requestBody">a request body if required</param>
 public Request(RESTHeaders headers, RestSharp.Method httpMethod, PathParams pathParameters, IQueryParams queryParameters, IRequestBody requestBody)
 {
     this.headers         = headers;
     this.httpMethod      = httpMethod;
     this.pathParameters  = pathParameters;
     this.queryParameters = queryParameters;
     this.requestBody     = requestBody;
 }
        public List <ICountry> GetCountries(IQueryParams queryParams = null)
        {
            var pipeline = new List <BsonDocument>();

            pipeline.Add(CountryMedalGroup);
            _applyQueryParams(pipeline, queryParams);
            return(_getCountryGroups(pipeline, queryParams));
        }
 public virtual object Auth0User(int userId, [FromServices] IQueryParams param)
 {
     using (var dbConnection = new SysDB())
     {
         var targetUserEmail = dbConnection.SysUser.First(user => user.UserID == userId).Email;
         return(new ManagementApiClient().GetUserByEmail(targetUserEmail));
     }
 }
Exemplo n.º 9
0
        public List <ICountry> GetCountries(IQueryParams queryParams = null)
        {
            var pipeline = new List <BsonDocument>();

            pipeline.Add(AthleteBsonUtil.Groups.Country);
            _applyQueryParams(pipeline, queryParams);
            return(_getCountryGroups(pipeline, queryParams));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Executes a Get request that returns the raw content.
        /// </summary>
        /// <param name="url">Request URL.</param>
        /// <param name="queryParams">Query string parameters.</param>
        /// <param name="client">REST client.</param>
        /// <returns></returns>
        protected static string GetRawContent(string url, IQueryParams queryParams = null, IVcRestClient client = null)
        {
            client = client ?? VcClient.GetRestClient();
            Request  request  = new Request(Method.Get, url, queryParams);
            Response response = client.Request(request);

            return(response.Content);
        }
Exemplo n.º 11
0
        public List <IAthlete> GetAthletes(string countryName, IQueryParams queryParams = null)
        {
            var pipeline = new List <BsonDocument>();

            pipeline.Add(GetAthleteCountyGroupMatch(countryName));
            var result = _getAthletes(pipeline, queryParams);

            return(result);
        }
Exemplo n.º 12
0
        public List <ICountry> GetCountries(int year, IQueryParams queryParams = null)
        {
            var pipeline = new List <BsonDocument>();

            pipeline.Add(GetAthleteYearGroupMatch(year));
            pipeline.Add(CountryMedalGroup);
            _applyQueryParams(pipeline, queryParams);
            return(_getCountryGroups(pipeline, queryParams));
        }
Exemplo n.º 13
0
        public List <ICountry> GetCountries(int year, IQueryParams queryParams = null)
        {
            var pipeline = new List <BsonDocument>();

            pipeline.Add(AthleteBsonUtil.Aggregates.Match(AthleteBsonUtil.Fields.Year, year));
            pipeline.Add(AthleteBsonUtil.Groups.Country);
            _applyQueryParams(pipeline, queryParams);
            return(_getCountryGroups(pipeline, queryParams));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Executes a Get request that returns a list.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">Request URL.</param>
        /// <param name="queryParams">Query string parameters.</param>
        /// <param name="client">REST client.</param>
        /// <returns></returns>
        protected static List <T> Get <T> (string url, IQueryParams queryParams = null, JsonConverter[] jsonConverters = null, IVcRestClient client = null) where T : IResourceEntity
        {
            client = client ?? VcClient.GetRestClient();
            Request  request  = new Request(Method.Get, url, queryParams);
            Response response = client.Request(request);
            JObject  json     = JObject.Parse(response.Content);

            return(JsonConvert.DeserializeObject <List <T> >(json.First.First.ToString(), jsonConverters));
        }
Exemplo n.º 15
0
        public List <IAthlete> GetAthletes(int year, IQueryParams queryParams = null)
        {
            var pipeline = new List <BsonDocument>();

            pipeline.Add(AthleteBsonUtil.Aggregates.Match(AthleteBsonUtil.Fields.Year, year));
            var result = _getAthletes(pipeline, queryParams);;

            return(result);
        }
Exemplo n.º 16
0
        public List <IAthlete> GetAthletes(string countryName, IQueryParams queryParams = null)
        {
            var pipeline = new List <BsonDocument>();

            pipeline.Add(AthleteBsonUtil.Aggregates.Match(AthleteBsonUtil.Fields.Country, countryName));
            var result = _getAthletes(pipeline, queryParams);

            return(result);
        }
Exemplo n.º 17
0
        public List <IAthlete> GetAthletes(int year, IQueryParams queryParams = null)
        {
            var pipeline = new List <BsonDocument>();

            pipeline.Add(GetAthleteYearGroupMatch(year));
            var result = _getAthletes(pipeline, queryParams);;

            return(result);
        }
Exemplo n.º 18
0
        public async Task <T> GetAll <T>(IQueryParams queryParams)
        {
            var url = $"{_baseUrl}/{_resource}";

            url += queryParams?.ToQueryParams();
            return(await url
                   .WithHeader("Authorization", _token)
                   .GetJsonAsync <T>());
        }
Exemplo n.º 19
0
        /// <summary>
        /// Executes a Count request.
        /// </summary>
        /// <param name="url">URL.</param>
        /// <param name="queryParams">Query parameters.</param>
        /// <param name="client">REST client.</param>
        /// <returns></returns>
        protected static int Count(string url, IQueryParams queryParams = null, IVcRestClient client = null)
        {
            client = client ?? VcClient.GetRestClient();
            Request  request  = new Request(Method.Get, url, queryParams);
            Response response = client.Request(request);
            JObject  json     = JObject.Parse(response.Content);

            return(JsonConvert.DeserializeObject <int>(json.First.First.ToString()));
        }
        public virtual object CheckUserExists([FromBody] NewUser newUser, [FromServices] IQueryParams param)
        {
            bool isUserExistant = false;

            using (var dbConnection = new SysDB())
            {
                isUserExistant = dbConnection.SysUser.Any(user => user.Email == newUser.Email);
            }
            return(new { userExistant = isUserExistant });
        }
Exemplo n.º 21
0
 private void _applyQueryParams(List <BsonDocument> pipeline, IQueryParams queryParams)
 {
     if (queryParams != null && queryParams.Sort != null)
     {
         pipeline.Add(
             GetSortDocument
             (
                 CountryFieldToBsonColumn(queryParams.SortProperty),
                 queryParams.Sort.Value)
             );
     }
 }
Exemplo n.º 22
0
 private void _applyQueryParams(List <BsonDocument> pipeline, IQueryParams queryParams)
 {
     if (queryParams != null && queryParams.Sort != null)
     {
         pipeline.Add(
             AthleteBsonUtil.Aggregates.Sort
             (
                 AthleteBsonUtil.CountryFieldtoBsonColumn(queryParams.SortProperty),
                 queryParams.Sort.Value)
             );
     }
 }
Exemplo n.º 23
0
        private List <IAthlete> _getAthletes(IEnumerable <BsonDocument> pipeline, IQueryParams queryParams)
        {
            var result = default(List <IAthlete>);
            IEnumerable <BsonDocument> groupAggregate;

            if (pipeline != null)
            {
                groupAggregate = athletes.Aggregate(new AggregateArgs {
                    Pipeline = pipeline
                });
            }
            else
            {
                groupAggregate = athletes.AsQueryable <BsonDocument>();
            }


            if (queryParams != null && queryParams.Count != null)
            {
                if (queryParams.Start != null)
                {
                    result = groupAggregate
                             .Skip(queryParams.Start.Value)
                             .Take(queryParams.Count.Value)
                             .Select(BsonSerializer.Deserialize <Athlete>)
                             .ToList <IAthlete>();
                }
                else
                {
                    result = groupAggregate
                             .Take(queryParams.Count.Value)
                             .Select(BsonSerializer.Deserialize <Athlete>)
                             .ToList <IAthlete>();
                }
            }
            else
            {
                result = groupAggregate
                         .Select(BsonSerializer.Deserialize <Athlete>)
                         .ToList <IAthlete>();
            }

            return(result);
        }
Exemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Request"/> class.
 /// </summary>
 /// <param name="method">HTTP method.</param>
 /// <param name="url">Request URL.</param>
 /// <param name="queryParams">Query string parameters.</param>
 public Request(string method, string url, IQueryParams queryParams)
 {
     Method      = method;
     Url         = url;
     QueryParams = queryParams;
 }
Exemplo n.º 25
0
 public IActionResult GetCSVMultiData([FromServices] IQueryParams param, [FromServices] IQueryFactory factory)
 {
     return(Ok(factory.GetData <List <DataReturn> >(param)));
 }
Exemplo n.º 26
0
        /// <summary>
        /// Looks up query method and invokes it
        /// </summary>
        /// <typeparam name="T">Return Type</typeparam>
        /// <param name="param">Query parameters</param>
        /// <returns></returns>
        //============================================================
        //Revision History
        //Date        Author          Description
        //06/28/2017  TB               Created
        //============================================================
        public T GetData <T>(IQueryParams param)
        {
            MethodInfo mi = Methods[param.QueryName];

            return((T)mi.Invoke(null, new object[] { param }));
        }
Exemplo n.º 27
0
 public IActionResult GetCSVData([FromServices] IQueryParams param, [FromServices] IQueryFactory factory)
 {
     return(Ok(factory.GetData <DataReturn>(param).Data));
 }
Exemplo n.º 28
0
 public TestService2(IQueryParams queryParams, AsyncObject asyncObject)
 {
     _queryParams = queryParams;
     _asyncObject = asyncObject;
 }
Exemplo n.º 29
0
 public void Test(IQueryParams queryParams, AsyncObject asyncObject, string test)
 {
     Console.WriteLine(DateTime.Now);
     Console.WriteLine();
     Response.UseCookie("session", "123456");
 }
Exemplo n.º 30
0
 public QueryAndForm(IQueryParams queryParams, IFormParams formParams)
 {
     _queryParams = queryParams;
     _formParams  = formParams;
 }