public async Task <IActionResult> DeletePhoto(int vehicleId, int photoId) { var vehicle = await context.Vehicles.SingleOrDefaultAsync(v => v.Id == vehicleId); if (vehicle == null) { return(NotFound()); } var uploadsFolderPath = Path.Combine(host.WebRootPath, "uploads"); var photo = await context.Photos.Where(p => p.VehicleId == vehicleId).SingleOrDefaultAsync(p => p.Id == photoId); if (photo == null) { return(NotFound()); } var filePath = Path.Combine(uploadsFolderPath, photo.FileName); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); context.Remove(photo); await context.SaveChangesAsync(); } else { return(BadRequest()); } return(Ok(filePath + " Deleted")); }
public async Task <IActionResult> DeleteVehicle(int id) { var vehicle = await context.Vehicles.SingleOrDefaultAsync(v => v.Id == id); if (vehicle == null) { return(NotFound()); } context.Remove(vehicle); await context.SaveChangesAsync(); return(Ok(id)); }