Example #1
0
        public ActionResult Details(int Id)
        {
            HttpResponseMessage response = WebClient.ApiClient.GetAsync($"Rentals/{Id}").Result;
            var rental = response.Content.ReadAsAsync <Rental>().Result;

            response = WebClient.ApiClient.GetAsync("Customers").Result;
            IList <Customer> customers = response.Content.ReadAsAsync <IList <Customer> >().Result;

            response = WebClient.ApiClient.GetAsync("Tools").Result;
            IList <Tool> dbTools = response.Content.ReadAsAsync <IList <Tool> >().Result;

            var customerRentalDetails = new CustomerRentalDetailsViewModel
            {
                Rental       = rental,
                CustomerName = customers.Select(cu => cu.CustomerName).FirstOrDefault(),
                RentedTools  = rental.RentalItems.Select(
                    ri => new CustomerToolViewModel
                {
                    RentalId = ri.RentalId,
                    ToolName = dbTools.Where(c2 => c2.ToolId == ri.ToolId).Select(m => m.Name).FirstOrDefault()
                }).ToList()
            };

            return(View(customerRentalDetails));
        }
Example #2
0
        public ActionResult Details(int Id)
        {
            HttpResponseMessage response = WebClient.ApiClient.GetAsync($"Rentals/{Id}").Result;
            var rental = response.Content.ReadAsAsync <Rental>().Result;

            response = WebClient.ApiClient.GetAsync("Customer").Result;
            IList <Customer> customers = response.Content.ReadAsAsync <IList <Customer> >().Result;

            response = WebClient.ApiClient.GetAsync("Inventory").Result;
            IList <Inventory> dbInventories = response.Content.ReadAsAsync <IList <Inventory> >().Result;

            var customerRentalDetails = new CustomerRentalDetailsViewModel
            {
                Rental      = rental,
                FName       = customers.Select(cu => cu.FName).FirstOrDefault(),
                LName       = customers.Select(cu => cu.LName).FirstOrDefault(),
                RentedTools = rental.RentalItems.Select(
                    ri => new CustomerToolsViewModel
                {
                    RentalId = ri.RentalId,
                    ToolType = dbInventories.Where(c2 => c2.AssetId == ri.AssetId).Select(m => m.ToolType).FirstOrDefault()
                }).ToList()
            };

            return(View(customerRentalDetails));
        }