public static ILinksWrapper Execute <TReadModel>
        (
            TReadModel queryResult,
            HttpContext httpContext,
            LinkGenerator generator
        )
        {
            switch (queryResult)
            {
            case EmployeeDetail:
                var employeeDetailLinks = new LinksWrapper <EmployeeDetail>
                {
                    Value = queryResult as EmployeeDetail,
                    Links = EmployeeLinkGenerator.CreateLinks(httpContext, generator, (queryResult as EmployeeDetail).EmployeeId)
                };

                return(employeeDetailLinks);

            case EmployeeAddressDetail:
                var addressDetailLinks = new LinksWrapper <EmployeeAddressDetail>
                {
                    Value = queryResult as EmployeeAddressDetail,
                    Links = EmployeeAddressLinkGenerator.CreateLinks(httpContext, generator, (queryResult as EmployeeAddressDetail).AddressId)
                };

                return(addressDetailLinks);

            case EmployeeContactDetail:
                var contactDetailLinks = new LinksWrapper <EmployeeContactDetail>
                {
                    Value = queryResult as EmployeeContactDetail,
                    Links = EmployeeContactLinkGenerator.CreateLinks(httpContext, generator, (queryResult as EmployeeContactDetail).PersonId)
                };

                return(contactDetailLinks);

            default:
                throw new ArgumentException("Unknown ReadModel", nameof(queryResult));
            }

            throw new NotImplementedException();
        }
Exemplo n.º 2
0
        public static ILinksWrapper Execute <TReadModel>
        (
            PagedList <TReadModel> queryResult,
            HttpContext httpContext,
            LinkGenerator generator
        )
        {
            switch (queryResult)
            {
            case PagedList <EmployeeListItem> :
                LinksWrapperList <EmployeeListItem> linksWrappers = new LinksWrapperList <EmployeeListItem>();
                var Employees = queryResult.ReadModels as IEnumerable <EmployeeListItem>;
                linksWrappers.MetaData = queryResult.MetaData;

                foreach (var listItem in Employees)
                {
                    var links = EmployeeLinkGenerator.CreateLinks(httpContext, generator, listItem.EmployeeId);

                    linksWrappers.Values.Add
                    (
                        new LinksWrapper <EmployeeListItem>
                    {
                        Value = listItem,
                        Links = links
                    }
                    );
                }

                return(linksWrappers);

            case PagedList <EmployeeListItemWithRoles> :
                LinksWrapperList <EmployeeListItemWithRoles> roleMemberLinksWrappers = new LinksWrapperList <EmployeeListItemWithRoles>();
                var roleMembers = queryResult.ReadModels as IEnumerable <EmployeeListItemWithRoles>;
                roleMemberLinksWrappers.MetaData = queryResult.MetaData;

                foreach (var listItem in roleMembers)
                {
                    var links = EmployeeLinkGenerator.CreateLinks(httpContext, generator, listItem.RoleId);

                    roleMemberLinksWrappers.Values.Add
                    (
                        new LinksWrapper <EmployeeListItemWithRoles>
                    {
                        Value = listItem,
                        Links = links
                    }
                    );
                }

                return(roleMemberLinksWrappers);

            case PagedList <EmployeeAddressListItem> :
                LinksWrapperList <EmployeeAddressListItem> addressLinksWrappers = new LinksWrapperList <EmployeeAddressListItem>();
                var EmployeeAddresses = queryResult.ReadModels as IEnumerable <EmployeeAddressListItem>;
                addressLinksWrappers.MetaData = queryResult.MetaData;

                foreach (var listItem in EmployeeAddresses)
                {
                    var links = EmployeeAddressLinkGenerator.CreateLinks(httpContext, generator, listItem.AddressId);

                    addressLinksWrappers.Values.Add
                    (
                        new LinksWrapper <EmployeeAddressListItem>
                    {
                        Value = listItem,
                        Links = links
                    }
                    );
                }

                return(addressLinksWrappers);

            case PagedList <EmployeeContactListItem> :
                LinksWrapperList <EmployeeContactListItem> contactLinksWrappers = new LinksWrapperList <EmployeeContactListItem>();
                var EmployeeContacts = queryResult.ReadModels as IEnumerable <EmployeeContactListItem>;
                contactLinksWrappers.MetaData = queryResult.MetaData;

                foreach (var listItem in EmployeeContacts)
                {
                    var links = EmployeeContactLinkGenerator.CreateLinks(httpContext, generator, listItem.PersonId);

                    contactLinksWrappers.Values.Add
                    (
                        new LinksWrapper <EmployeeContactListItem>
                    {
                        Value = listItem,
                        Links = links
                    }
                    );
                }

                return(contactLinksWrappers);

            default:
                throw new ArgumentException("Unknown ReadModel", nameof(queryResult));
            }
        }