示例#1
0
        public async Task <FilmReview> LeaveScore(Film film, User user, int score)
        {
            FilmReview userFilmReview = await _unitOfWork.FilmReviewRepository.GetUserFilmReview(user.ID, film.ID);

            if (userFilmReview == null)
            {
                userFilmReview = new FilmReview()
                {
                    FilmID = film.ID,
                    UserID = user.ID,
                    Score  = score,
                    Date   = DateTime.Now
                };

                userFilmReview = await _unitOfWork.FilmReviewRepository.Create(userFilmReview);
            }
            else
            {
                userFilmReview.Score = score;

                userFilmReview = await _unitOfWork.FilmReviewRepository.Update(userFilmReview.ID, userFilmReview);
            }

            await _unitOfWork.SaveAsync();

            return(userFilmReview);
        }
示例#2
0
 ///<summary>
 /// Converts FilmReview object to FilmReviewViewModel
 ///</summary>
 ///<param name="review"> FilmReview object to map from</param>
 ///<returns>Mapped instance of type <see cref="FilmReviewViewModel"/></returns>
 public FilmReviewViewModel MapToFilmReviewViewMode(FilmReview review)
 {
     return(new FilmReviewViewModel
     {
         Content = review.Content,
         CreatedOn = review.CreatedOn,
         UserGender = review.User.Gender,
         Username = review.User.UserName,
     });
 }
示例#3
0
        /// <summary>
        /// Update the selected review if exists
        /// </summary>
        /// <param name="filmReview">An updated review of the film</param>
        public async Task UpdateAsync(FilmReview filmReview)
        {
            var filmInContext = await context.FilmReviews.FindAsync(filmReview.Id);

            if (filmInContext != null)
            {
                context.Entry(filmInContext).CurrentValues.SetValues(filmReview);
                await context.SaveChangesAsync();
            }
        }
示例#4
0
 public async Task AddUpdateFilmReview(FilmReview filmReview)
 {
     if (filmReview.Id != 0)
     {
         await MobileService.GetTable <FilmReview>().UpdateAsync(filmReview);
     }
     else
     {
         await MobileService.GetTable <FilmReview>().InsertAsync(filmReview);
     }
 }
        public async Task LeaveScore_WithNotExistingUserScore_ReturnsNewFilmReview()
        {
            User user  = CreateUser();
            Film film  = CreateFilm();
            int  score = 4;

            _mockUnitOfWork.Setup(s => s.FilmReviewRepository.Create(It.IsAny <FilmReview>()))
            .ReturnsAsync(CreateFilmReview(user, film, It.IsAny <string>(), score));

            FilmReview filmReview = await _leaveReviewService.LeaveScore(film, user, score);

            Assert.AreEqual(score, filmReview.Score);
        }
        public async Task LeaveReview_WithNotExistingUserReview_ReturnsNewFilmReview()
        {
            User   user       = CreateUser();
            Film   film       = CreateFilm();
            string reviewText = "test review text";
            int    score      = 5;

            _mockUnitOfWork.Setup(s => s.FilmReviewRepository.Create(It.IsAny <FilmReview>()))
            .ReturnsAsync(CreateFilmReview(user, film, reviewText, score));

            FilmReview filmReview = await _leaveReviewService.LeaveReview(film, user, reviewText, score);

            Assert.AreEqual(reviewText, filmReview.ReviewText);
            Assert.AreEqual(score, filmReview.Score);
        }
        public async Task LeaveScore_WithExistingUserScore_ReturnsUpdatedFilmScore()
        {
            User       user               = CreateUser();
            Film       film               = CreateFilm();
            int        score              = 5;
            int        updatedScore       = 8;
            FilmReview existingFilmReview = CreateFilmReview(user, film, It.IsAny <string>(), score);

            _mockUnitOfWork.Setup(s => s.FilmReviewRepository.GetUserFilmReview(user.ID, film.ID)).ReturnsAsync(existingFilmReview);
            _mockUnitOfWork.Setup(s => s.FilmReviewRepository.Update(It.IsAny <int>(), existingFilmReview))
            .ReturnsAsync(CreateFilmReview(user, film, It.IsAny <string>(), updatedScore));

            FilmReview filmReview = await _leaveReviewService.LeaveScore(film, user, updatedScore);

            Assert.AreEqual(updatedScore, filmReview.Score);
        }
示例#8
0
        public void InsertFilmReview(FilmReview review)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                var command = new SqlCommand(String.Format("Select * from FilmReview WHERE Id={0}", Id), connection);

                try
                {
                    command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                }
            }
        }
示例#9
0
        public static void WriteReview(User user, Film film, string text, int value)
        {
            var review = new FilmReview {
                Text = text
            };

            review.User.Add(user);
            review.Artwork.Add(film);
            review.Save();

            film.Reviews.Add(review);

            Evaluate(user, film, value);

            Repository.SaveChanges();
        }
示例#10
0
        public async Task LeaveReview_WithExistingUserReview_ReturnsUpdatedFilmReview()
        {
            User       user               = CreateUser();
            Film       film               = CreateFilm();
            string     reviewText         = "test review text";
            int        score              = 5;
            string     updatedReviewText  = "updated test review text";
            int        updatedScore       = 8;
            FilmReview existingFilmReview = CreateFilmReview(user, film, reviewText, score);

            _mockUnitOfWork.Setup(s => s.FilmReviewRepository.GetUserFilmReview(user.ID, film.ID)).ReturnsAsync(existingFilmReview);
            _mockUnitOfWork.Setup(s => s.FilmReviewRepository.Update(It.IsAny <int>(), existingFilmReview))
            .ReturnsAsync(CreateFilmReview(user, film, updatedReviewText, updatedScore));

            FilmReview filmReview = await _leaveReviewService.LeaveReview(film, user, updatedReviewText, updatedScore);

            Assert.AreEqual(updatedScore, filmReview.Score);
            Assert.AreEqual(updatedReviewText, filmReview.ReviewText);
        }
示例#11
0
        public async Task <IActionResult> CreateReview([Bind("ReviewSummary, ReviewRating, FilmFk")] FilmReview aReview)
        {
            if (ModelState.IsValid)
            {
                int userPK = Int32.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Sid).Value);
                aReview.ContactFk = userPK;
                _context.Add(aReview);
                await _context.SaveChangesAsync();

                var reviewedFilm = await _context.Film.FirstOrDefaultAsync(f => f.FilmPk == aReview.FilmFk);

                TempData["message"] = $"Review of {reviewedFilm.MovieTitle} added successfully";
                return(RedirectToAction("Index", "Account"));
            }
            else
            {
                return(View());
            }
        }
        public async Task AddAsyncAddsElementToDb()
        {
            // Arrange
            var reviews = new List <FilmReview>
            {
                new FilmReview {
                },
                new FilmReview {
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <FilmReview> >();

            mockSet.As <IQueryable <FilmReview> >().Setup(m => m.Provider).Returns(reviews.Provider);
            mockSet.As <IQueryable <FilmReview> >().Setup(m => m.Expression).Returns(reviews.Expression);
            mockSet.As <IQueryable <FilmReview> >().Setup(m => m.ElementType).Returns(reviews.ElementType);
            mockSet.As <IQueryable <FilmReview> >().Setup(m => m.GetEnumerator()).Returns(reviews.GetEnumerator());

            var mockContext = new Mock <CinemaDbContext>();

            mockContext.Setup(c => c.FilmReviews).Returns(mockSet.Object);
            mockContext.Setup(m => m.AddAsync(It.IsAny <FilmReview>(), It.IsAny <CancellationToken>()))
            .Returns(new ValueTask <EntityEntry <FilmReview> >(Task.FromResult((EntityEntry <FilmReview>)null)));

            var filmReviewBusiness = new FilmReviewBusiness(mockContext.Object);
            var mapper             = new Mapper();
            var filmReview         = new FilmReview {
            };

            // Act
            await filmReviewBusiness.AddAsync(filmReview);

            // Assert
            mockSet.Verify(m => m.AddAsync(It.IsAny <FilmReview>(), It.IsAny <CancellationToken>()), Times.Once());
            mockContext.Verify(m => m.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once());
        }
        private async void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.rating.Value == 0)
            {
                MessageBox.Show(String.Format("please rate this {0}", ReviewTarget.ToString()));
                return;
            }

            this.SpinAndWait(true);

            this.UserReview.Reviewer = String.IsNullOrWhiteSpace(this.tbName.Text) ? "anonymous" : this.tbName.Text;
            this.UserReview.Review   = this.tbReview.Text.Trim();
            this.UserReview.Rating   = Convert.ToInt16(this.rating.Value);
            this.UserReview.ReviewTS = DateTime.Now;
            this.UserReview.UserId   = ExtendedPropertyHelper.GetUserIdentifier();

            Config.UserName = this.UserReview.Reviewer;

            try
            {
                if (ReviewTarget == ReviewTargetDef.Film)
                {
                    FilmReview fr = (FilmReview)this.UserReview;
                    fr.Movie = SelectedFilm.EDI;

                    if (this.UserReview.Id != 0)
                    {
                        await App.MobileService.GetTable <FilmReview>().UpdateAsync(fr);
                    }
                    else
                    {
                        await App.MobileService.GetTable <FilmReview>().InsertAsync(fr);
                    }
                }
                else
                {
                    CinemaReview cr = (CinemaReview)this.UserReview;
                    cr.Cinema = SelectedCinema.ID;

                    if (this.UserReview.Id != 0)
                    {
                        await App.MobileService.GetTable <CinemaReview>().UpdateAsync(cr);
                    }
                    else
                    {
                        await App.MobileService.GetTable <CinemaReview>().InsertAsync(cr);
                    }
                }
            }
            catch
            {
                MessageBox.Show("error saving review. please try again later");
            }

            this.SpinAndWait(false);

            if (this.NavigationService.CanGoBack)
            {
                this.NavigationService.GoBack();
            }
        }
示例#14
0
        /// <summary>
        /// Adds a new review in the database
        /// </summary>
        /// <param name="filmReview">The review to add</param>
        public async Task AddAsync(FilmReview filmReview)
        {
            await context.FilmReviews.AddAsync(filmReview);

            await context.SaveChangesAsync();
        }