Example #1
0
        private async Task SubmitReview()
        {
            if (!ValidateEmpty())
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please fill out the required fields (Review Text, Rating)", "OK");

                return;
            }
            bool v = await ValidateReviewExists();

            if (!v)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "You can't review the same album more than once!", "OK");
            }
            else
            {
                ReviewUpsertRequest request = new ReviewUpsertRequest()
                {
                    AlbumId    = ThisAlbumId,
                    Rating     = int.Parse(Rating),
                    ReviewText = ReviewText,
                    UserId     = APIService.loggedProfile.UserId
                };
                SetFavProperties();
                request.FavouriteSongs      = FavTracks;
                request.LeastFavouriteSongs = LeastFavTracks;
                var inserted = await _reviewService.Insert <Review>(request);

                await _postSerivce.Insert <Post>(new PostUpsertRequest()
                {
                    AdminName       = APIService.loggedProfile.Username,
                    ArtistRelatedId = LoadedAlbum.ArtistId,
                    IsGlobal        = false,
                    Opphoto         = APIService.loggedProfile.UserPhoto,
                    PostDateTime    = DateTime.Now,
                    PostPhoto       = LoadedAlbum.AlbumPhoto,
                    PostText        = ReviewText + "\n \n " + "Favorite tracks: " + FavTracks + "\n \n " + "Least favorite tracks: " + LeastFavTracks + "\n \n" +
                                      "Rating: " + Rating,
                    PostTitle = "Album Review: " +
                                LoadedAlbum.AlbumName,
                    ReviewRelatedId = inserted.ReviewId,
                    UserRelatedId   = APIService.loggedProfile.UserId
                });

                await GlobalMethods.GenerateRating(ThisAlbumId);

                await Application.Current.MainPage.DisplayAlert("Success", "Review successfully added! You will now be redirected to the album page.", "OK");

                PopHandler?.Invoke(this, null);
            }
        }