public async Task <Comment> CreateAsync(Comment comment) { context.Add(comment); await context.SaveChangesAsync(); return(comment); }
public async Task <IActionResult> Create([Bind("Id,Title,Description")] Photo photo, IFormFile thePicture) { if (ModelState.IsValid) { photo.UserName = User.Identity.Name; photo.DateUploaded = DateTime.Now; using MemoryStream memoryStream = new MemoryStream(); await thePicture.CopyToAsync(memoryStream); photo.Picture = memoryStream.ToArray(); photo.ContentType = thePicture.ContentType; _context.Add(photo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(photo)); }