public async Task <IActionResult> OnPost() { if (Makina != null) { var path = Path.Combine(ihostingEnvironment.WebRootPath, "images", Photo.FileName); var stream = new FileStream(path, FileMode.Create); await Photo.CopyToAsync(stream); Makina.ImageName = Photo.FileName; Makina.MarkaId = MarkaId; Makina.ModeliId = ModelId; await _services.AddMakinat(Makina); return(RedirectToPage("Index")); } return(RedirectToPage("Index")); }
public IActionResult OnPost() { if (this.Makina.ImageName != null) { var path1 = Path.Combine(hostingEnvironment.ContentRootPath, "wwwroot/images", Makina.ImageName); if (System.IO.File.Exists(path1)) { System.IO.File.Delete(path1); } } var path = Path.Combine(hostingEnvironment.WebRootPath, "images", Photo.FileName); var stream = new FileStream(path, FileMode.Create); Photo.CopyToAsync(stream); Makina.ImageName = Photo.FileName; _services.UpdateMakina(Makina); return(RedirectToPage("Index")); }
/// <summary> /// Updates a vehicle /// </summary> /// <param name="license">License of vehicle</param> /// <returns>Redirect to index if success, if fail to same page.</returns> public IActionResult OnPostUpdate(string license) { if (ModelState.ErrorCount == 1) { Vehicle.License = license; if (Photo != null) { var path = Path.Combine(ihostingEnvironment.WebRootPath, "images", Vehicle.License + " - " + "car.png"); using (var stream = new FileStream(path, FileMode.Create)) { Photo.CopyToAsync(stream); Vehicle.Vehicle_Image = "car.png"; } } if (VehiclesRepository.UpdateVehicle(Vehicle)) { return(RedirectToPage("Index")); } } return(Page()); }