public IActionResult AddPhoto(PhotoModel model, int?albumId) { if (ModelState.IsValid) { var photo = new Domain.Photo() { AlbumId = albumId, PostId = null, MIMEType = model.Binar.ContentType }; using (var memoryStream = new MemoryStream()) { model.Binar.CopyTo(memoryStream); photo.Binary = memoryStream.ToArray(); } photoService.AddPhoto(photo); return(RedirectToAction("Album", "Profile", new { albumId = model.AlbumId })); } if (albumId == null) { return(NotFound()); } AlbumViewerModel albumViewerModel = new AlbumViewerModel() { PhotoModel = model, HasThisAlbum = albumService.HasThisAlbum(albumId.Value), Id = albumId.Value, Name = albumService.GetAlbum(albumId.Value).Name }; return(View("Album", albumViewerModel)); }
public IActionResult AddPost(PostAddModel post) { if (ModelState.IsValid) { var newPost = mapper.Map <Post>(post); postService.AddPost(newPost); if (post.Binar != null) { var photo = new Photo() { Position = 1, PostId = newPost.Id, MIMEType = post.Binar.ContentType }; using (var memoryStream = new MemoryStream()) { post.Binar.CopyTo(memoryStream); photo.Binary = memoryStream.ToArray(); } photoService.AddPhoto(photo); } return(RedirectToAction("Index")); } return(View("Index", post)); }