public async Task <IActionResult> AddCarToUser(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var user = await _context.Users.FirstOrDefaultAsync(m => m.Id == id);

            if (user == null)
            {
                return(NotFound());
            }

            var userCarViewModel = new UserCarViewModel()
            {
                UserId       = user.Id,
                AllCarBrands = LicensePlateSearcher.GetAllBrands().Select(x => new SelectListItem
                {
                    Text  = x,
                    Value = x.ToString()
                }),
                AllCarModels = LicensePlateSearcher.GetAllModels().Select(x => new SelectListItem
                {
                    Text  = x,
                    Value = x.ToString()
                })
            };

            return(View(userCarViewModel));
        }
Exemple #2
0
        public IActionResult CreatePath(UserViewModel user)
        {
            var path = new Path()
            {
                User = new User()
                {
                    Name = ""
                },
                AllCarBrands = LicensePlateSearcher.GetAllBrands().Select(x => new SelectListItem
                {
                    Text  = x,
                    Value = x.ToString()
                }),
                AllCarModels = LicensePlateSearcher.GetAllModels().Select(x => new SelectListItem
                {
                    Text  = x,
                    Value = x.ToString()
                }),
                AllCars = LicensePlateSearcher.GetAllCars().Select(x => new SelectListItem
                {
                    Text  = x.Brand,
                    Value = x.Make.ToString().Replace(';', ' ') + $" - ({x.Range}km)"
                }),
                Cars = _context.Cars.ToList()
            };

            if (user.Name == null)
            {
                path.User.Name = "Gästläge";
            }
            else
            {
                path.User = _context.Users.Where(x => x.Name == user.Name && x.Phone == user.Phone && x.Password == user.Password).Include(x => x.UserCars).ThenInclude(x => x.Car).FirstOrDefault();
            }

            return(View(path));
        }