public virtual async Task <IHttpActionResult> Get([FromUri] Guid id)
        {
            short schoolYearFromRoute = Convert.ToInt16(RequestContext.RouteData.Values["schoolYearFromRoute"]);

            var response = await UpstreamEdFiApiInvoker.Get(
                _v3TypeForV2Type.Value,
                Request.Headers,
                Request.GetQueryNameValuePairs(),
                schoolYearFromRoute,
                id);

            if (response.Status == HttpStatusCode.OK)
            {
                var v3Model = DeserializeFromV3Stream(response.ResponseStream, isCollection: false);
                var v2Model = WebApiApplication.Mapper.Map <TResourceReadModel>(
                    v3Model,
                    opts =>
                {
                    opts.Items.Add("Invoker", UpstreamEdFiApiInvoker);
                    opts.Items.Add("Headers", Request.Headers);
                    opts.Items.Add("SchoolYear", schoolYearFromRoute);
                });

                return(Ok(v2Model));
            }

            var httpResponseMessage = CreateResponseMessage(response);

            return(new ResponseMessageResult(httpResponseMessage));
        }
        public virtual async Task <IHttpActionResult> GetAll(
            [FromUri] UrlQueryParametersRequest urlQueryParametersRequest,
            [FromUri] TGetByExampleRequest request = default(TGetByExampleRequest))
        {
            short schoolYearFromRoute = Convert.ToInt16(RequestContext.RouteData.Values["schoolYearFromRoute"]);

            var v2RequestAsReadModel = new TResourceReadModel();

            MapAll(request, v2RequestAsReadModel as TEntityInterface);

            var v3RequestAsReadModel = MapV2ReadModelToV3ReadModel(v2RequestAsReadModel, schoolYearFromRoute);

            var upstreamQueryParams = MapReadModelToQueryParameters(v3RequestAsReadModel);

            var response = await UpstreamEdFiApiInvoker.Get(
                _v3TypeForV2Type.Value,
                Request.Headers,
                upstreamQueryParams,
                schoolYearFromRoute);

            if (response.Status == HttpStatusCode.OK)
            {
                IList v3Models = (IList)DeserializeFromV3Stream(response.ResponseStream, isCollection: true);

                var v2Models = new List <TResourceReadModel>();

                foreach (var v3Model in v3Models)
                {
                    var v2Model = WebApiApplication.Mapper.Map <TResourceReadModel>(
                        v3Model,
                        opts =>
                    {
                        opts.Items.Add("Invoker", UpstreamEdFiApiInvoker);
                        opts.Items.Add("Headers", Request.Headers);
                        opts.Items.Add("SchoolYear", schoolYearFromRoute);
                    });

                    v2Models.Add(v2Model);
                }

                return(Ok(v2Models));
            }


            var httpResponseMessage = CreateResponseMessage(response);

            return(new ResponseMessageResult(httpResponseMessage));
        }
        protected IHttpActionResult GetByKey(TGetByKeyRequest request)
        {
            short schoolYearFromRoute = Convert.ToInt16(RequestContext.RouteData.Values["schoolYearFromRoute"]);

            var v2RequestAsReadModel = new TResourceReadModel();

            MapKey(request, v2RequestAsReadModel as TEntityInterface);

            var v3RequestAsReadModel = MapV2ReadModelToV3ReadModel(v2RequestAsReadModel, schoolYearFromRoute);

            var upstreamQueryParams = MapReadModelToQueryParameters(v3RequestAsReadModel);

            var response = UpstreamEdFiApiInvoker.Get(
                _v3TypeForV2Type.Value,
                Request.Headers,
                upstreamQueryParams,
                schoolYearFromRoute)
                           .ConfigureAwait(false)
                           .GetAwaiter()
                           .GetResult();

            if (response.Status == HttpStatusCode.OK)
            {
                var v3Models = DeserializeFromV3Stream(response.ResponseStream, isCollection: true);

                if ((v3Models as IList).Count == 0)
                {
                    return(NotFound());
                }
                else
                {
                    var v2Model = WebApiApplication.Mapper.Map <TResourceReadModel>(
                        (v3Models as IList)[0],
                        opts =>
                    {
                        opts.Items.Add("Invoker", UpstreamEdFiApiInvoker);
                        opts.Items.Add("Headers", Request.Headers);
                        opts.Items.Add("SchoolYear", schoolYearFromRoute);
                    });

                    return(Ok(v2Model));
                }
            }

            var httpResponseMessage = CreateResponseMessage(response);

            return(new ResponseMessageResult(httpResponseMessage));
        }