public async Task <IActionResult> Create([FromForm] Infovideo infovideo, IFormFile Poster) { if (Poster.Length > 0) //Convert Image to byte and save to database { byte[] p1 = null; using (var fs1 = Poster.OpenReadStream()) using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } // установка массива байтов infovideo.Poster = p1; } _context.Add(infovideo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), "Home/Index")); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Opisanie,Date,Producer,User,Poster")] Infovideo infovideo, IFormFile Poster) { if (id != infovideo.Id) { return(NotFound()); } var infovideo1 = await _context.Infovideos.FindAsync(id); if (Poster != null) //Convert Image to byte and save to database { byte[] p1 = null; using (var fs1 = Poster.OpenReadStream()) using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } // установка массива байтов infovideo.Poster = p1; } else { infovideo.Poster = infovideo1.Poster; } _context.Entry(infovideo1).CurrentValues.SetValues(infovideo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), "Home/Index")); }