public async Task<IActionResult> Edit(int id, [Bind("CharacterId,Name,Hunger,Sleep,Awake,Fun,Currency,UserId")] Character character) { if (id != character.CharacterId) { return NotFound(); } if (ModelState.IsValid) { try { _context.Update(character); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CharacterExists(character.CharacterId)) { return NotFound(); } else { throw; } } return RedirectToAction(nameof(Index)); } ViewData["UserId"] = new SelectList(_context.User, "UserId", "UserId", character.UserId); return View(character); }
public async Task <IActionResult> Edit(FileDetail detail) { if (ModelState.IsValid) { try { List <BlobSummary> Blobs = new List <BlobSummary>(); for (int i = 0; i < Request.Form.Files.Count; i++) { var file = Request.Form.Files[i]; if (file != null) { var fileName = Path.GetFileName(file.FileName); BlobSummary summary = new BlobSummary() { FileName = fileName, Extension = Path.GetExtension(fileName), Id = Guid.NewGuid(), Blob = GenerateBlob(file), ContentType = Request.Form.Files[i].ContentType }; Blobs.Add(summary); _context.Entry(summary).State = EntityState.Added; } } detail.Modified = DateTime.Now; detail.Blobs = Blobs; // _context.Entry(detail).State = EntityState.Modified; _context.Update(detail); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateConcurrencyException) { if (!FileDetailExists(detail.Id)) { return(NotFound()); } else { throw; } } } return(View(detail)); }