Exemplo n.º 1
0
        public async Task <ResponseViewModel <CarViewModel> > Get()
        {
            try
            {
                using (var robo = new AutomobileIndexPage())
                {
                    var result = await robo.GetCars();

                    var response = new ResponseViewModel <CarViewModel>();
                    response.Message = "";
                    response.Data    = result.Select(x => new CarViewModel
                    {
                        Model    = x.Model,
                        Price    = x.Price,
                        Link     = x.Link,
                        ImageUrl = x.ImageUrl
                    }).ToList();

                    return(response);
                }
            }
            catch (Exception ex)
            {
                return(new ResponseViewModel <CarViewModel> {
                    Message = ex.Message,
                    Data = new List <CarViewModel>()
                });
            }
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <CarViewModel> > GetCars()
        {
            try
            {
                using (var robo = new AutomobileIndexPage())
                {
                    var result = await robo.GetCars();

                    return(result.Select(x => new CarViewModel
                    {
                        Model = x.Model,
                        Price = x.Price,
                        Link = x.Link,
                        ImageUrl = x.ImageUrl
                    }).ToList());;
                }
            }
            catch (System.Exception ex)
            {
                return(new List <CarViewModel>());
            }
        }