//Get CarUpdate public ActionResult CarUpdate(int id) { User user = (User)Session["LoginUser"]; CarsRepository carRepository = new CarsRepository(); CarPhotoRepository carPhotoRepository = new CarPhotoRepository(); var result = carRepository.GetByFilter(x => x.UserId == user.Id && x.Id == id).FirstOrDefault(); var photoresult = carPhotoRepository.GetByFilter(x => x.CarId == id).FirstOrDefault(); CarViewModel carView = new CarViewModel(); carView.Id = id; carView.Brand = result.Brand; carView.CarPlate = result.CarPlate; carView.CaseType = result.CaseType; carView.Color = result.Color; carView.Engine = result.Engine; carView.EnginePower = result.EnginePower; carView.Fuel = result.Fuel; carView.Gear = result.Gear; carView.Km = result.Km; carView.Model = result.Model; carView.Photo = photoresult.Photo; carView.Price = result.Price; carView.Sherry = result.Sherry; carView.Traction = result.Traction; carView.Waranty = result.Waranty; carView.Year = result.Year; return(View()); }
public ActionResult CarUpdate(CarViewModel model) { User user = (User)Session["LoginUser"]; CarsRepository carsRepository = new CarsRepository(); CarPhotoRepository carPhotoRepository = new CarPhotoRepository(); var result = carsRepository.GetByFilter(x => x.UserId == user.Id && x.Id == model.Id).FirstOrDefault(); var resultcar = carsRepository.UpdateCar(new Cars { Id = result.Id, Brand = result.Brand, CarPlate = result.CarPlate, CaseType = result.CaseType, Color = result.Color, Engine = result.Engine, EnginePower = result.EnginePower, Fuel = result.Fuel, Gear = result.Gear, Km = result.Km, Model = result.Model, Price = result.Price, Sherry = result.Sherry, Traction = result.Traction, Waranty = result.Waranty, Year = result.Year, RegisterDate = DateTime.Now, IsDelete = false }); var carphotoresult = carPhotoRepository.GetByFilter(x => x.CarId == result.Id).FirstOrDefault(); carPhotoRepository.UpdateCarPhoto(new CarPhoto { Id = carphotoresult.Id, CarId = result.Id, Photo = model.Photo }); TempData["Mesaj"] = resultcar ? new TempDataDictionary { { "class", "alert-success" }, { "Msg", "Kayıt başarıyla güncellendi." } } : new TempDataDictionary { { "class", "alert-danger" }, { "Msg", "Kayıt güncellenemedi bilgilerini kontrol et." } }; return(View()); }