public ActionResult ShowLessServiceForm(Car car)
        {
            var service     = _context.Services.Where(c => c.CarId == car.Id).OrderByDescending(c => c.DateAdded).ToList();
            var serviceList = new List <Service>();
            int i           = 0;

            foreach (var item in service)
            {
                i++;
                if (i <= 5)
                {
                    serviceList.Add(item);
                }
            }

            var viewModel = new CarAndServiceViewModel
            {
                Car          = car,
                Services     = serviceList,
                CheckInteger = i,
                ServiceType  = _context.ServiceTypes.ToList()
            };

            return(View(viewModel));
        }
示例#2
0
        // GET: CarServices
        public ActionResult ViewServices(Car car)
        {
            using (var client = new HttpClient())
            {
                //client.BaseAddress = new Uri("https://localhost:44346/api/");
                client.BaseAddress = new Uri("https://garageproject20190808114242.azurewebsites.net/api/");
                var responsetask = client.GetAsync("servicescar?id=" + car.Id);
                responsetask.Wait();

                var result = responsetask.Result;
                JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter();
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <IEnumerable <CarService> >();
                    readTask.Wait();

                    var viewModel = new CarAndServiceViewModel()
                    {
                        CarServices     = readTask.Result,
                        Cars            = car,
                        PendingRequests = RequestsList()
                    };
                    return(View(viewModel));
                }
            }
            return(View());
        }
示例#3
0
        public ActionResult AddServices(CarAndServiceViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                viewModel.Service.DateAdded = DateTime.Today;
                viewModel.Service.CarId     = viewModel.Car.Id;
                var car = _context.Cars.Find(viewModel.Car.Id);

                _context.Services.Add(viewModel.Service);
                _context.SaveChanges();

                return(RedirectToAction("AddNewServices", "Car", car));
            }
            viewModel.Car         = _context.Cars.Find(viewModel.Car.Id);
            viewModel.Services    = _context.Services.Where(c => c.CarId == viewModel.Car.Id).OrderByDescending(c => c.DateAdded).ToList();
            viewModel.ServiceType = _context.ServiceTypes.ToList();
            return(View("AddNewServices", viewModel));

            //if(!ModelState.IsValid)
            //{

            //    viewModel.ServiceType = _context.ServiceTypes.ToList();
            //    viewModel.Services = _context.Services.ToList();

            //    return View("AddNewServices", viewModel);
            //}
            //viewModel.Service.DateAdded = DateTime.Today;
            //viewModel.Service.CarId = viewModel.Car.Id;
            //var car = _context.Cars.Find(viewModel.Car.Id);

            //_context.Services.Add(viewModel.Service);
            //_context.SaveChanges();

            //return RedirectToAction("AddNewServices", "Car", car);
        }
示例#4
0
        public ActionResult AddServices(CarAndServiceViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                viewModel.Service.DateAdded = DateTime.Today;
                viewModel.Service.CarId     = viewModel.Car.Id;


                HttpResponseMessage response1 = GlobalVariables.WebApiClient.GetAsync("Cars/" + viewModel.Car.Id).Result;
                var car = response1.Content.ReadAsAsync <Car>().Result;
                //var car = _context.Cars.Find(viewModel.Car.Id);

                HttpResponseMessage response2 = GlobalVariables.WebApiClient.PostAsJsonAsync("Service/", viewModel.Service).Result;

                //_context.Services.Add(viewModel.Service);
                //_context.SaveChanges();

                return(RedirectToAction("AddNewServices", "Car", car));
            }

            viewModel.Car      = _context.Cars.Find(viewModel.Car.Id);
            viewModel.Services = _context.Services.Where(c => c.CarId == viewModel.Car.Id).OrderByDescending(c => c.DateAdded).ToList();

            viewModel.ServiceType = _context.ServiceTypes.ToList();

            return(View("AddNewServices", viewModel));
        }
示例#5
0
        public ActionResult AddNewServices(Car car)
        {
            HttpResponseMessage response1 = GlobalVariables.WebApiClient.GetAsync("Service").Result;
            var            services       = response1.Content.ReadAsAsync <IEnumerable <Service> >().Result;
            List <Service> pastServices   = new List <Service>();

            foreach (var v in services)
            {
                if (v.CarId == car.Id)
                {
                    pastServices.Add(v);
                }
            }
            pastServices.Reverse();
            //var service = _context.Services.Where(c => c.CarId == car.Id).OrderByDescending(c => c.DateAdded).ToList();

            HttpResponseMessage response2 = GlobalVariables.WebApiClient.GetAsync("ServiceTypes").Result;
            var serviceType = response2.Content.ReadAsAsync <IEnumerable <ServiceType> >().Result;

            //List<ServiceType> serviceType = _context.ServiceTypes.ToList();

            var viewModel = new CarAndServiceViewModel
            {
                Car         = car,
                Services    = pastServices,
                ServiceType = serviceType
            };

            return(View(viewModel));
        }
示例#6
0
        public ActionResult Create(Car car)
        {
            var viewModel = new CarAndServiceViewModel()
            {
                CarServicesDbs = GetCarServicesDb(),
                Cars           = car
            };

            return(View(viewModel));
        }
        public ActionResult ServiceForm(Car car)
        {
            var viewModel = new CarAndServiceViewModel
            {
                Cars         = car,
                ServiceTypes = _context.ServiceTypes.ToList()
            };

            return(View(viewModel));
        }
        public ActionResult AddNewServices(Car car)
        {
            var service = _context.Services.Where(c => c.CarId == car.Id).OrderByDescending(c => c.DateAdded).ToList();

            List <ServiceType> serviceType = _context.ServiceTypes.ToList();

            var viewModel = new CarAndServiceViewModel
            {
                Car         = car,
                Services    = service,
                ServiceType = serviceType
            };

            return(View(viewModel));
        }
示例#9
0
        public ActionResult AddNewServices(Car car)
        {
            var                user        = _context.Users.Where(c => c.Id.Equals(car.UserId)).SingleOrDefault();
            List <Service>     service     = _context.Services.Where(c => c.CarId == car.Id).ToList();
            List <ServiceType> serviceType = _context.ServiceTypes.ToList();

            var viewModel = new CarAndServiceViewModel()
            {
                User        = user,
                Car         = car,
                Services    = service,
                ServiceType = serviceType
            };

            return(View(viewModel));
        }
        public ActionResult AddService(CarAndServiceViewModel carAndService)
        {
            if (ModelState.IsValid)
            {
                //carAndService.Service.DateAdded = DateTime.Today;
                carAndService.Service.CarId = carAndService.Cars.Id;
                _context.Services.Add(carAndService.Service);
                _context.SaveChanges();
                var car = _context.Cars.Find(carAndService.Cars.Id);
                return(RedirectToAction("Service", "Service", car));
            }
            var model = new CarAndServiceViewModel
            {
                ServiceTypes = _context.ServiceTypes.ToList()
            };

            return(View("ServiceForm", model));
        }
示例#11
0
        public ActionResult Create(CarAndServiceViewModel viewModel)
        {
            //viewModel.ServiceCar.CarId = viewModel.Cars.Id;
            //viewModel.ServiceCar.DateAdded = DateTime.Today;

            var vM = new ServiceRequest()
            {
                CarId         = viewModel.Cars.Id,
                DateRequested = DateTime.Today,
                Details       = viewModel.ServiceCar.Details,
                Miles         = viewModel.ServiceCar.Miles,
                Price         = viewModel.ServiceCar.Price,
                ServiceType   = viewModel.ServiceCar.ServiceType,
                UserId        = User.Identity.GetUserId()
            };

            //db.ServiceRequests.Add(vM);
            //db.SaveChanges();

            AddServiceReq(vM);

            return(RedirectToAction("Index", "User"));
        }