public async Task <IActionResult> Create(FavoriteCars favoriteCars) { favoriteCars.Userid = User.FindFirst(ClaimTypes.NameIdentifier).Value; _context.Add(favoriteCars); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> AddToFavorites(int CarID) { FavoriteCars fc = new FavoriteCars(); fc.Userid = User.FindFirst(ClaimTypes.NameIdentifier).Value; fc.Carid = CarID; Cars car = await _dal.GetCar(CarID); fc.Color = car.Color; fc.Make = car.Make; fc.Model = car.Model; fc.Year = car.Year; _context.Add(fc); _context.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult AddCarToFavorites(Car car) { AspNetUsers thisUser = _context.AspNetUsers.Where(u => u.UserName == User.Identity.Name).First(); FavoriteCars newCar = new FavoriteCars(); newCar.CarId = car.Id; newCar.Make = car.Make; newCar.Model = car.Model; newCar.Year = car.Year; newCar.Color = car.Color; newCar.UserId = thisUser.Id; newCar.User = thisUser; if (ModelState.IsValid) { _context.FavoriteCars.Add(newCar); _context.SaveChanges(); return(RedirectToAction("ListCars", "Car")); } return(View("ListCars")); }
public IActionResult RemoveFromFavorites(FavoriteCars car) { _context.FavoriteCars.Remove(car); _context.SaveChanges(); return(RedirectToAction("GetFavoritesList")); }