void ReleaseDesignerOutlets() { if (DescriptionLabel != null) { DescriptionLabel.Dispose(); DescriptionLabel = null; } if (HeightLabel != null) { HeightLabel.Dispose(); HeightLabel = null; } if (NameLabel != null) { NameLabel.Dispose(); NameLabel = null; } if (PokemonImage != null) { PokemonImage.Dispose(); PokemonImage = null; } if (WeightLabel != null) { WeightLabel.Dispose(); WeightLabel = null; } }
public static async Task <bool> ProcessImages(ICollection <IFormFile> files, Pokemon pokemon, PokedexContext _context, IHostingEnvironment _environment, ModelStateDictionary m) { if (m.IsValid) { if (pokemon.ID == 0) { List <HarvestItem> h = pokemon.Harvestables.Where(harvestable => harvestable.IsHarvestable).ToList(); _context.Pokemon.Add(pokemon); } else { _context.Pokemon.Update(pokemon); } await _context.SaveChangesAsync(); var uploadDir = Path.Combine(_environment.WebRootPath, $"images\\pokemon\\{pokemon.Name.ToLower()}"); foreach (var file in files) { if (file.Length > 0) { var fileGuid = Guid.NewGuid(); if (!Directory.Exists(uploadDir)) { Directory.CreateDirectory(uploadDir); } var fsName = $"{fileGuid.ToString()}.{Path.GetExtension(file.FileName)}"; var filePath = Path.Combine(uploadDir, fsName); var pokemonImage = new PokemonImage() { Pokemon = pokemon, Active = true, Caption = "", ImageName = file.FileName, FileSystemName = fsName, PokemonID = pokemon.ID }; using (var fs = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(fs); } _context.PokemonImages.Add(pokemonImage); } } if (_context.ChangeTracker.HasChanges()) { await _context.SaveChangesAsync(); } return(true); } return(false); }
private PokemonImage GetImage(string fileName) { try { var pb = new PokemonImage(fileName); pb.Size = new Size(120, 150); return(pb); } catch (Exception e) { return(null); } }