Beispiel #1
0
        public IActionResult GetProducts([FromQuery] ProductParameters productParameters)
        {
            var products = _repository.Product.GetProducts(productParameters);

            var metadata = new
            {
                products.TotalCount,
                products.PageSize,
                products.CurrentPage,
                products.TotalPages,
                products.HasNext,
                products.HasPrevious
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));

            _logger.LogInfo($"Returned {products.TotalCount} products from database.");
            var shapedProducts = products.Select(o => o.Entity).ToList();
            var mediaType      = (MediaTypeHeaderValue)HttpContext.Items["AcceptHeaderMediaType"];

            if (!mediaType.SubTypeWithoutSuffix.EndsWith("hateoas", StringComparison.InvariantCultureIgnoreCase))
            {
                return(Ok(shapedProducts));
            }

            for (var index = 0; index < products.Count; index++)
            {
                var productLinks = CreateLinksForProduct(products[index].Id, productParameters.Fields);
                shapedProducts[index].Add("Links", productLinks);
            }
            var productsWrapper = new LinkCollectionWrapper <Entity>(shapedProducts);

            return(Ok(CreateLinksForProducts(productsWrapper)));
        }
Beispiel #2
0
        private LinkResponse ReturnLinkedEmployees(
            IEnumerable <EmployeeDto> employeesDtos,
            string fields,
            Guid companyId,
            HttpContext httpContext,
            List <Entity> shapedEmployees
            )
        {
            var employeeDtoList = employeesDtos.ToList();

            for (var index = 0; index < employeeDtoList.Count(); index++)
            {
                var employeeLinks = CreateLinksForEmployee(
                    httpContext,
                    companyId,
                    employeeDtoList[index].Id,
                    fields
                    );
                shapedEmployees[index].Add("Links", employeeLinks);
            }

            var employeeCollection = new LinkCollectionWrapper <Entity>(shapedEmployees);
            var linkedEmployees    = CreateLinksForEmployees(httpContext, employeeCollection);

            return(new LinkResponse {
                HasLinks = true, LinkedEntities = linkedEmployees
            });
        }
Beispiel #3
0
 private LinkCollectionWrapper <Entity> CreateLinksForEmployees(HttpContext httpContext,
                                                                LinkCollectionWrapper <Entity> employeesWrapper)
 {
     employeesWrapper.Links.Add(new Link(_linkGenerator.GetUriByAction(httpContext, "GetEmployeesByCompany",
                                                                       values: new { }), "self", "GET"));
     return(employeesWrapper);
 }
Beispiel #4
0
        private LinkCollectionWrapper <Entity> CreateLinksForOwners(LinkCollectionWrapper <Entity> ownersWrapper)
        {
            ownersWrapper.Links.Add(new Link(_linkGenerator.GetUriByAction(HttpContext, nameof(GetAllOwners), values: new { }),
                                             "self",
                                             "GET"));

            return(ownersWrapper);
        }
        private LinkCollectionWrapper <Entity> CreateLinksForVotings(LinkCollectionWrapper <Entity> votingsWrapper)
        {
            votingsWrapper.Links.Add(new Link(_linkGenerator.GetUriByAction(HttpContext, nameof(GetVotings), values: new { }),
                                              "self",
                                              "GET"));

            return(votingsWrapper);
        }
Beispiel #6
0
        private LinkCollectionWrapper <Entity> CreateLinksForProducts(LinkCollectionWrapper <Entity> productsWrapper)
        {
            productsWrapper.Links.Add(new Link(_linkGenerator.GetUriByAction(HttpContext, nameof(GetProducts), values: new { }),
                                               "self",
                                               "GET"));

            return(productsWrapper);
        }
Beispiel #7
0
        private LinkCollectionWrapper <Entity> CreateLinksForCategorys(LinkCollectionWrapper <Entity> categoriesWrapper)
        {
            categoriesWrapper.Links.Add(new Link(_linkGenerator.GetUriByAction(HttpContext, nameof(GetCategories), values: new { }),
                                                 "self",
                                                 "GET"));

            return(categoriesWrapper);
        }
Beispiel #8
0
        private LinkCollectionWrapper <Entity> CreateLinksForCourses(HttpContext httpContext,
                                                                     LinkCollectionWrapper <Entity> coursesWrapper)
        {
            coursesWrapper.Links.Add(new Link(_linkGenerator.GetUriByAction(httpContext,
                                                                            "GetCoursesForOrganization", values: new { }),
                                              "self",
                                              "GET"));

            return(coursesWrapper);
        }
Beispiel #9
0
 private LinkCollectionWrapper <Entity> CreateLinksForPokemons(HttpContext context,
                                                               LinkCollectionWrapper <Entity> pokemonWrapper)
 {
     pokemonWrapper.Links.Add(new Link(_linkGenerator.GetUriByAction(context, "GetPokemons",
                                                                     "Pokemons",
                                                                     values: new{ }),
                                       "self",
                                       "GET"));
     return(pokemonWrapper);
 }
Beispiel #10
0
        internal static LinkCollectionWrapper GetInstance()
        {
            LinkCollection real = default(LinkCollection);

            RealInstanceFactory(ref real);
            var instance = (LinkCollectionWrapper)LinkCollectionWrapper.GetWrapper(real);

            InstanceFactory(ref instance);
            if (instance == null)
            {
                Assert.Inconclusive("Could not Create Test Instance");
            }
            return(instance);
        }
Beispiel #11
0
        private LinkResponse ReturnLinkedAccounts(IEnumerable <AccountDTO> accountDTOs, string fields, HttpContext httpContext, List <Entity> shapedAccounts)
        {
            var accountDTOsList = accountDTOs.ToList();

            for (int index = 0; index < accountDTOsList.Count; index++)
            {
                List <Link> accountLinks = CreateLinksForAccount(httpContext, accountDTOsList[index].AccountId, fields);
                shapedAccounts[index].Add("Links", accountLinks);
            }

            var accountCollection = new LinkCollectionWrapper <Entity>(shapedAccounts);
            LinkCollectionWrapper <Entity> linkedAccounts = CreateLinksForAccount(httpContext, accountCollection);

            return(new LinkResponse {
                HasLinks = true, LinkedEntites = linkedAccounts
            });
        }
Beispiel #12
0
        private LinkResponse ReturnLinkedPokemons(IEnumerable <PokemonDto> pokemons, string fields,
                                                  HttpContext context, List <Entity> shapedPokemons)
        {
            var pokemonsList = pokemons.ToList();

            for (var i = 0; i < pokemonsList.Count; i++)
            {
                var pokemonLinks = CreateLinksForPokemon(context, pokemonsList[i].Id, fields);
                shapedPokemons[i].Add("Links", pokemonLinks);
            }
            var pokemonCollection = new LinkCollectionWrapper <Entity>(shapedPokemons);
            var linkedPokemons    = CreateLinksForPokemons(context, pokemonCollection);

            return(new LinkResponse {
                HasLinks = true, LinkedShapedObjects = linkedPokemons
            });
        }
        private LinkResponse ReturnLinkedCategories(IEnumerable <CategoryDTO> categoriesDTO, string fields, HttpContext httpContext, List <Entity> shapedCategories)
        {
            var categoriesDTOList = categoriesDTO.ToList();

            for (var index = 0; index < categoriesDTOList.Count(); index++)
            {
                var categoryLinks = CreateLinksForCategory(httpContext, categoriesDTOList[index].Id, fields);
                shapedCategories[index].Add("Links", categoryLinks);
            }

            var categoryCollection = new LinkCollectionWrapper <Entity>(shapedCategories);
            var linkedCategories   = CreateLinksForCategories(httpContext, categoryCollection);

            return(new LinkResponse {
                HasLinks = true, LinkedEntities = linkedCategories
            });
        }
Beispiel #14
0
        private LinkResponse ReturnLinkdedArticulos(IEnumerable <ArticuloDto> articuloDto, string fields, int articuloId, HttpContext httpContext, List <Entity> shapedArticulos)
        {
            var articuloDtoList = articuloDto.ToList();

            for (var index = 0; index < articuloDtoList.Count(); index++)
            {
                var employeeLinks = CreateLinksForArticulo(httpContext, articuloId, articuloDtoList[index].articuloId, fields);
                shapedArticulos[index].Add("Links", employeeLinks);
            }

            var articuloCollection = new LinkCollectionWrapper <Entity>(shapedArticulos);
            var linkedEmployees    = CreateLinksForEmployees(httpContext, articuloCollection);

            return(new LinkResponse {
                HasLinks = true, LinkedEntities = linkedEmployees
            });
        }
Beispiel #15
0
        private LinkResponse ReturnLinkdedCourses(IEnumerable <CourseDto> coursesDto,
                                                  string fields, Guid orgId, HttpContext httpContext, List <Entity> shapedCourses)
        {
            var courseDtoList = coursesDto.ToList();

            for (var index = 0; index < courseDtoList.Count(); index++)
            {
                var courseLinks = CreateLinksForCourse(httpContext, orgId, courseDtoList[index].Id, fields);
                shapedCourses[index].Add("Links", courseLinks);
            }

            var courseCollection = new LinkCollectionWrapper <Entity>(shapedCourses);
            var linkedcourses    = CreateLinksForCourses(httpContext, courseCollection);

            return(new LinkResponse {
                HasLinks = true, LinkedEntities = linkedcourses
            });
        }
        public IActionResult GetOwners([FromQuery] OwnerParameters ownerParameters)
        {
            if (!ownerParameters.ValidYearRange)
            {
                return(BadRequest("Max year of birth cannot be less than min year of birth"));
            }

            var owners = _repository.Owner.GetOwners(ownerParameters);

            var metadata = new
            {
                owners.TotalCount,
                owners.PageSize,
                owners.CurrentPage,
                owners.TotalPages,
                owners.HasNext,
                owners.HasPrevious
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));

            _logger.LogInfo($"Returned {owners.TotalCount} owners from database.");

            var shapedOwners = owners.Select(o => o.Entity).ToList();

//			var mediaType = (MediaTypeHeaderValue)HttpContext.Items["AcceptHeaderMediaType"];
            var mediaType = HttpContext.Request.Headers["AcceptHeaderMediaType"];


            if (!mediaType.Contains("hateoas"))
            {
                return(Ok(shapedOwners));
            }

            for (var index = 0; index < owners.Count(); index++)
            {
                var ownerLinks = CreateLinksForOwner(owners[index].Id, ownerParameters.Fields);
                shapedOwners[index].Add("Links", ownerLinks);
            }

            var ownersWrapper = new LinkCollectionWrapper <Entity>(shapedOwners);

            return(Ok(CreateLinksForOwners(ownersWrapper)));
        }
        public async Task <IActionResult> GetAllOwners([FromQuery] OwnerParameters ownerParameters)
        {
            if (!ownerParameters.ValidYearRange)
            {
                return(BadRequest("Max year of birth cannot be less than min year of birth"));
            }

            var owners = await this._repository.Owner.GetAllOwnersAsync(ownerParameters);

            var metadata = new
            {
                owners.TotalCount,
                owners.PageSize,
                owners.CurrentPage,
                owners.TotalPages,
                owners.HasNext,
                owners.HasPrevious
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));

            _logger.LogInfo($"Returned {owners.TotalCount} owners from database.");

            var shapedOwners = owners.Select(o => o.Entity).ToList();

            var mediaType = (Microsoft.Net.Http.Headers.MediaTypeHeaderValue)HttpContext.Items["AcceptHeaderMediaType"];

            if (!mediaType.SubTypeWithoutSuffix.EndsWith("hateoas", StringComparison.InvariantCultureIgnoreCase))
            {
                return(Ok(shapedOwners));
            }

            for (var index = 0; index < owners.Count(); index++)
            {
                var ownerLinks = CreateLinksForOwner(owners[index].Id, ownerParameters.Fields);
                shapedOwners[index].Add("Links", ownerLinks);
            }

            var ownersWrapper = new LinkCollectionWrapper <Entity>(shapedOwners);

            return(Ok(CreateLinksForOwners(ownersWrapper)));
        }
Beispiel #18
0
        public IActionResult GetAllOwners([FromQuery] OwnerParameters ownerParameters)
        {
            try
            {
                if (!ownerParameters.ValidYearRange)
                {
                    return(BadRequest("Max year of birth cannot be less than min year of birth"));
                }

                var owners = _repository.Owner.GetOwners(ownerParameters);

                var metadata = new
                {
                    owners.TotalCount,
                    owners.PageSize,
                    owners.CurrentPage,
                    owners.TotalPages,
                    owners.HasNext,
                    owners.HasPrevious
                };

                Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));

                var shapedOwners = owners.Select(o => o.Entity).ToList();

                for (var index = 0; index < owners.Count(); index++)
                {
                    var ownerLinks = CreateLinksForOwner(owners[index].Id, ownerParameters.fields);
                    shapedOwners[index].Add("Links", ownerLinks);
                }

                var ownersWrapper = new LinkCollectionWrapper <Entity>(shapedOwners);

                return(Ok(CreateLinksForOwners(ownersWrapper)));
            }

            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside GetAllOwners action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
Beispiel #19
0
        public IActionResult GetAccountsForOwner(Guid ownerId, [FromQuery] AccountParameters parameters)
        {
            var accounts = _repository.Account.GetAccountsByOwner(ownerId, parameters);

            var metadata = new
            {
                accounts.TotalCount,
                accounts.PageSize,
                accounts.CurrentPage,
                accounts.TotalPages,
                accounts.HasNext,
                accounts.HasPrevious
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));

            _logger.LogInfo($"Returned {accounts.TotalCount} accounts from database.");

            var shapedAccounts = accounts.Select(o => o.Entity).ToList();

            var mediaType = HttpContext.Request.Headers["AcceptHeaderMediaType"];


            if (!mediaType.Contains("hateoas"))
            {
                return(Ok(shapedAccounts));
            }

            for (var index = 0; index < accounts.Count(); index++)
            {
                var accountLinks = CreateLinksForAccount(ownerId, accounts[index].Id, parameters.Fields);
                shapedAccounts[index].Add("Links", accountLinks);
            }

            var accountsWrapper = new LinkCollectionWrapper <Entity>(shapedAccounts);

            return(Ok(CreateLinksForAccounts(accountsWrapper)));
        }
Beispiel #20
0
        private LinkCollectionWrapper <Entity> CreateLinksForEmployees(HttpContext httpContext, LinkCollectionWrapper <Entity> articulosWrapper)
        {
            articulosWrapper.Links.Add(new Link(_linkGenerator.GetUriByAction(httpContext, "GetArticulosForCategoria", values: new { }),
                                                "self",
                                                "GET"));

            return(articulosWrapper);
        }
Beispiel #21
0
        private LinkCollectionWrapper <Entity> CreateLinksForAccount(HttpContext httpContext, LinkCollectionWrapper <Entity> accountsWrapper)
        {
            accountsWrapper.Links.Add(new Link(_linkGenerator.GetUriByAction(httpContext,
                                                                             "GetAccounts", values: new { }),
                                               "self",
                                               "GET"));

            return(accountsWrapper);
        }
Beispiel #22
0
 static partial void InstanceFactory(ref LinkCollectionWrapper instance, [CallerMemberName] string callerName = "");