public ActionResult UploadPicture(HttpPostedFileBase file, int albumId) { if (file == null) { throw new NullReferenceException("File is null!"); } if (file.IsImage()) { var image = file.HttpPostedFileBaseToImage().ImageToByteArray(); var albumPhoto = new AlbumPhoto() { Photo = image, Likes = new List<Like>(), Comments = new List<Comment>(), AlbumId = albumId }; this.Data.AlbumPhotos.Add(albumPhoto); this.Data.SaveChanges(); } else { throw new ArgumentException("File is not image"); } return RedirectToAction("PhotosInAlbum", new { id = albumId }); }