public ActionResult Create(FormCollection collection) { var image = Request.Files["image"]; byte[] imageData = null; if (image != null) { using (System.IO.BinaryReader br = new System.IO.BinaryReader(image.InputStream)) { imageData = br.ReadBytes(image.ContentLength); } } try { var album = new Album { Name = collection.GetValue("name").AttemptedValue, DateOfCreation = DateTime.Parse(collection.GetValue("dateOfCreation").AttemptedValue), Compositions = new List <Composition>(), Performer = performerRepository.GetEntity(int.Parse(collection.GetValue("performer").AttemptedValue)), Image = imageData }; if (!albumRepository.AddEntity(album)) { throw new InvalidOperationException("Error during album creation"); } return(RedirectToAction("Search", "Albums")); } catch { ViewBag.Error = "Error during album creation"; return(RedirectToAction("Create", "Albums")); } }