示例#1
0
        public async Task <IActionResult> GetAll()
        {
            var items = await _productRepository.ListAllAsync();

            var results = Mapper.Map <IEnumerable <ProductViewModel> >(items);

            return(Ok(results));
        }
示例#2
0
        public async Task <IActionResult> GetAll()
        {
            var items = await _vehicleRepository.ListAllAsync();

            var vehicleVms = Mapper.Map <IEnumerable <VehicleViewModel> >(items);

            vehicleVms = vehicleVms.Select(CreateLinksForVehicle);
            var wrapper = new LinkedCollectionResourceWrapperViewModel <VehicleViewModel>(vehicleVms);

            return(Ok(CreateLinksForVehicle(wrapper)));
        }
示例#3
0
        public async Task <IActionResult> GetAll(string fields)
        {
            var items = await _customerRepository.ListAllAsync();

            var results              = Mapper.Map <IEnumerable <CustomerViewModel> >(items);
            var dynamicList          = results.ToDynamicIEnumerable(fields);
            var links                = CreateLinksForCustomers(fields);
            var dynamicListWithLinks = dynamicList.Select(customer =>
            {
                var customerDictionary = customer as IDictionary <string, object>;
                var customerLinks      = CreateLinksForCustomer(
                    (int)customerDictionary["Id"], fields);
                customerDictionary.Add("links", customerLinks);
                return(customerDictionary);
            });
            var resultWithLink = new
            {
                Value = dynamicListWithLinks,
                Links = links
            };

            return(Ok(resultWithLink));
        }