Exemple #1
0
        public IActionResult AddOwnerCar(int?id)
        {
            IEnumerable <CarDTO>       carDTOs      = carService.GetCars();
            IEnumerable <CarViewModel> carViewModel = Mapper.Map <IEnumerable <CarDTO>, IEnumerable <CarViewModel> >(carDTOs);

            CarOwnerViewModel carOwnerViewModel = new CarOwnerViewModel()
            {
                OwnerId = id.GetValueOrDefault(),
            };

            ViewBag.CarsToChose = new List <CarViewModel>(carViewModel);
            return(View(carOwnerViewModel));
        }
        //Показывает владельцов машины с заданным ID
        public ActionResult Owners(int id)
        {
            CarOwnerViewModel model = new CarOwnerViewModel
            {
                Owners = from u in _carOwnerRepository.CarOwners
                         from inf in _ownerRepository.Owners
                         where (u.OwnerId == inf.OwnerId && u.CarId == id)
                         select inf,
                CarId = id
            };

            return(View(model));
        }
        //Новый владелец
        public PartialViewResult NewOwner(int carId)
        {
            CarOwnerViewModel model = new CarOwnerViewModel
            {
                CarId  = carId,
                Owners = from o in _ownerRepository.Owners
                         select o,
                list = from i in _ownerRepository.Owners
                       select new SelectListItem
                {
                    Text  = i.FullName,
                    Value = i.OwnerId.ToString()
                }
            };

            return(PartialView("_CreateOwnerForCar", model));
        }
Exemple #4
0
        public IActionResult CarOwner(int?id)  // for car all owners
        {
            if (id != null)
            {
                CarOwnerViewModel CarOwner = new CarOwnerViewModel
                {
                    Car = db.Cars.FirstOrDefault(x => x.Id == id)
                };

                if (CarOwner.Car != null)
                {
                    var ownersIds = db.CarOwners
                                    .Where(carOwner => carOwner.CarId == id)
                                    .Select(y => y.OwnerId)
                                    .ToHashSet();
                    CarOwner.Owners = db.Owners
                                      .Where(x => ownersIds.Contains(x.Id))
                                      .ToList();

                    return(View(CarOwner));
                }
            }
            return(NotFound());
        }
Exemple #5
0
        public IActionResult AddOwnerCar(CarOwnerViewModel carOwnerViewModel)
        {
            ownerService.AddCarForOwner(carOwnerViewModel.OwnerId, carOwnerViewModel.CarId);

            return(RedirectToAction("Index"));
        }