Esempio n. 1
0
        public async Task <ActionResult <IEnumerable <FaceShapeLinks> > > GetFaceShapeLinks(
            [FromQuery(Name = "limit")] string limit   = "1000",
            [FromQuery(Name = "offset")] string offset = "0",
            [FromQuery(Name = "search")] string search = ""
            )
        {
            if (!_authorizationService.ValidateJWTToken(Request))
            {
                return(Unauthorized(new { errors = new { Token = new string[] { "Invalid token" } }, status = 401 }));
            }

            if (limit != null && offset != null)
            {
                if (int.TryParse(limit, out int l) && int.TryParse(offset, out int o))
                {
                    var limitedFaceShapeLinks = await _context
                                                .FaceShapeLinks
                                                .Include(fsl => fsl.FaceShape)
                                                .Where(
                        fsl =>
                        fsl
                        .LinkName
                        .Trim()
                        .ToLower()
                        .Contains(string.IsNullOrWhiteSpace(search) ?                                             search :
                                  search.Trim().ToLower()
                                  ) ||
                        fsl.LinkUrl.Trim().ToLower().Contains(string.IsNullOrWhiteSpace(search) ? search : search.Trim().ToLower())
                        )
                                                .Skip(o)
                                                .Take(l)
                                                .ToListAsync();

                    return(Ok(new { faceShapeLinks = limitedFaceShapeLinks }));
                }
                else
                {
                    return(BadRequest(new { errors = new { queries = new string[] { "Invalid queries" }, status = 400 } }));
                }
            }

            var faceShapeLinks = await _context.FaceShapeLinks.Include(fsl => fsl.FaceShape).ToListAsync();

            return(Ok(new { faceShapeLinks = faceShapeLinks }));
        }
        public async Task <ActionResult <IEnumerable <Colours> > > GetColours(
            [FromQuery(Name = "limit")] string limit   = "1000",
            [FromQuery(Name = "offset")] string offset = "0",
            [FromQuery(Name = "search")] string search = ""
            )
        {
            if (!_authorizationService.ValidateJWTToken(Request))
            {
                return(Unauthorized(new { errors = new { Token = new string[] { "Invalid token" } }, status = 401 }));
            }

            if (limit != null && offset != null)
            {
                if (int.TryParse(limit, out int l) && int.TryParse(offset, out int o))
                {
                    var limitedColours = await _context
                                         .Colours
                                         .Where(
                        r =>
                        r.ColourName.Trim().ToLower().Contains(string.IsNullOrWhiteSpace(search) ? search : search.Trim().ToLower()) ||
                        r.ColourHash.Trim().ToLower().Contains(string.IsNullOrWhiteSpace(search) ? search : search.Trim().ToLower())
                        )
                                         .Skip(o)
                                         .Take(l)
                                         .ToListAsync();

                    return(Ok(new { colours = limitedColours }));
                }
                else
                {
                    return(BadRequest(new { errors = new { queries = new string[] { "Invalid queries" }, status = 400 } }));
                }
            }

            // default return
            var colours = await _context.Colours.ToListAsync();

            return(Ok(new { colours = colours }));
        }