public async Task <IActionResult> Edit(int id, [Bind("Id,EntranceId")] qvEntrancePhoto qvEntrancePhoto, IFormFile Photo) { if (id != qvEntrancePhoto.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (Photo != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(Photo.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)Photo.Length); } // установка массива байтов qvEntrancePhoto.Photo = imageData; } _context.Update(qvEntrancePhoto); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!qvEntrancePhotoExists(qvEntrancePhoto.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Details", "qvEntrances", new { id = qvEntrancePhoto.EntranceId })); } ViewData["EntranceId"] = new SelectList(_context.Entrances, "Id", "Id", qvEntrancePhoto.EntranceId); return(View(qvEntrancePhoto)); }
public async Task <IActionResult> Create([Bind("Id,EntranceId")] qvEntrancePhoto qvEntrancePhoto, IFormFile Photo) { if (ModelState.IsValid) { if (Photo != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(Photo.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)Photo.Length); } // установка массива байтов qvEntrancePhoto.Photo = imageData; } _context.Add(qvEntrancePhoto); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "qvEntrances", new { id = qvEntrancePhoto.EntranceId })); } ViewData["EntranceId"] = new SelectList(_context.Entrances, "Id", "Id", qvEntrancePhoto.EntranceId); return(View(qvEntrancePhoto)); }