public HttpResponseMessage PostVoteForAlbum(VoteModel vote, int albumId, string sessionKey) { try { var userService = new UserService(); var user = userService.GetUserBySessionKey(sessionKey); Validator.ValidateUser(user, "Cannot vote album"); var albumService = new AlbumService(); var album = albumService.GetAlbumById(albumId); Validator.ValidateAlbum(album, ALBUM_NOT_FOUND); var isVoted = album.Votes.Count(v => v.User.Id == user.Id) > 0; if (isVoted) { throw new Exception("Already voted.."); } var newVote = albumService.AddVoteToAlbum(vote, album, user); var albumToReturn = new AlbumModel() { Category = new CategoryModel() { Id = album.Category.Id, Name = album.Category.Name }, Comments = from comment in album.Comments select new CommentModel() { Text = comment.Text, UserName = comment.User.UserName, CreatedAt = comment.CreatedAt }, CreatedAt = album.CreatedAt, Id = album.Id, MainImageUrl = album.Pictures.Count > 0 ? album.Pictures.First().Url : "", Pictures = from picture in album.Pictures select new PictureModel() { CreateDate = picture.CreateDate, Description = picture.Description, Id = picture.Id, Title = picture.Title, Url = picture.Url }, Title = album.Title, User = new UserModel() { CreatedAt = album.User.CreatedAt, Email = album.User.Email, Id = album.User.Id, UserName = album.User.UserName }, PositiveVotes = album.Votes.Count(v => v.isPositive == true), NegativeVotes = album.Votes.Count(v => v.isPositive == false) }; return(this.Request.CreateResponse(HttpStatusCode.OK, albumToReturn)); } catch (Exception ex) { return(this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message)); } }