public IActionResult Edit(ChangeBikeViewModel model) { if (ModelState.IsValid) { var bike = _bikeService.GetBikeById(model.Id); if (bike != null) { if (model.BikeImg != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(model.BikeImg.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)model.BikeImg.Length); } bike.Name = model.Name; bike.MaxSpeed = model.MaxSpeed; bike.TypeEngine = model.TypeEngine; bike.Power = model.Power; bike.Fuel = model.Fuel; bike.Description = model.Description; bike.Price = model.Price; bike.BikeImg = imageData; var result = _bikeService.Update(bike); if (result == true) { _commitProvider.Save(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Index")); } } } } return(View(model)); }
public IActionResult Edit(int id) { var res = _bikeService.GetBikeById(id); if (res == null) { return(NotFound()); } ChangeBikeViewModel model = new ChangeBikeViewModel { Id = res.Id, Name = res.Name, MaxSpeed = res.MaxSpeed, TypeEngine = res.TypeEngine, Power = res.Power, Fuel = res.Fuel, Description = res.Description, Price = res.Price }; return(View(model)); }