public async Task <IActionResult> CreateAlbum(CreateAlbumModel model) { if (ModelState.IsValid) { AlbumPicture albumPicture = new AlbumPicture(); using (var memoryStream = new MemoryStream()) { await model.PictureOne.CopyToAsync(memoryStream); albumPicture.PictureOne = memoryStream.ToArray(); if (model.PictureTwo != null) { await model.PictureTwo.CopyToAsync(memoryStream); albumPicture.PictureTwo = memoryStream.ToArray(); } } bool result = await repository.CreateAlbumPicAsync(albumPicture); if (result) { Album album = new Album { AlbumName = model.AlbumName, ArtistId = model.ArtistId, GenreId = model.GenreId, ReleaseYear = model.ReleaseYear, AlbumPictureId = albumPicture.AlbumPictureId }; result = await repository.CreateAlbumAsync(album); if (result) { return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "An error occured while creating the Album"); } } else { ModelState.AddModelError("", "An error occured while creating the Album pictures"); } } return(View(model)); }