public void SaveVehicleFleet(VehicleFleetItem entity) { if (entity.Id == default) { context.Entry(entity).State = EntityState.Added; } else { context.Entry(entity).State = EntityState.Modified; } context.SaveChanges(); }
public IActionResult Edit(VehicleFleetItem model, IFormFile titleImageFile) { if (ModelState.IsValid) { if (titleImageFile != null) { model.TitleImagePath = titleImageFile.FileName; using (var stream = new FileStream(Path.Combine(hostingEnvironment.WebRootPath, "images/", titleImageFile.FileName), FileMode.Create)) { titleImageFile.CopyTo(stream); } } dataManager.VehicleFleet.SaveVehicleFleet(model); return(RedirectToAction(nameof(HomeController.Index), nameof(HomeController).CutController())); } return(View(model)); }