Ejemplo n.º 1
0
        public async Task CreateWithUser_ShouldCreateAndReturnCount()
        {
            this.Initialize();
            this.SeedUser();

            var input = new CreateReviewInputModel()
            {
                Title         = Title,
                Content       = Content,
                GivenRating   = GivenRating,
                ProductId     = ProductId,
                KeepFitUserId = UserId
            };

            var expectedCount = 1;
            var actual        = await this.service.CreateAsync(input);

            var user   = this.context.Users.Include(x => x.Reviews).First();
            var review = user.Reviews.First();

            Assert.Equal(expectedCount, actual);
            Assert.Equal(expectedCount, user.Reviews.Count);
            Assert.Equal(Title, review.Title);
            Assert.Equal(Content, review.Content);
            Assert.Equal(ProductId, review.ProductId);
        }
        public async Task CreateMovieReviewShouldReturnFalseIfReviewAlreadyExists()
        {
            var user1 = new MovieDatabaseUser
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                AvatarLink = "avatar",
            };
            var artist1 = new Artist
            {
                FullName  = "name1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            var movie1 = new Movie
            {
                Name        = "movie1",
                ReleaseDate = DateTime.Parse("24 July 2019"),
                Description = "description1",
                Length      = 160,
                Genre       = new Genre {
                    Name = "genre1"
                },
                Director       = artist1,
                CoverImageLink = "cover1",
                TrailerLink    = "trailer1",
            };
            var movieReview1 = new MovieReview
            {
                Movie   = movie1,
                User    = user1,
                Content = "content1",
                Rating  = 8,
                Date    = DateTime.Parse("27 July 2019"),
            };
            await dbContext.Movies.AddAsync(movie1);

            await dbContext.MovieReviews.AddAsync(movieReview1);

            await dbContext.SaveChangesAsync();

            var movieId = movie1.Id;
            var userId  = user1.Id;

            var reviewService = new ReviewService(dbContext, mapper);

            var input = new CreateReviewInputModel
            {
                Id      = movieId,
                Content = "content1",
                Rating  = 8,
            };

            var actualResult = await reviewService.CreateMovieReviewAsync(userId, input);

            Assert.False(actualResult);
            Assert.True(dbContext.MovieReviews.Count() == 1);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(CreateReviewInputModel input)
        {
            var userId = this.userManager.GetUserId(this.User);

            await this.reviewsService.Create(input.PlaceId, userId, input.Comment, input.Rating);

            return(this.RedirectToAction("GetById", "Places", new { id = input.PlaceId }));
        }
Ejemplo n.º 4
0
 private void GenerateContributionInfo(CreateReviewInputModel createReviewModel)
 {
     if (OneRadio.Checked)
     {
         ContributionPriceTextBox.Text = ReviewPriceTextBox.Text;
         ReviewNumberComboBox.Text     = createReviewModel.ReviewHeader;
     }
 }
Ejemplo n.º 5
0
        public void CreateReview(CreateReviewInputModel model)
        {
            StringBuilder InsertIntoReviewQuerySb = new StringBuilder();

            InsertIntoReviewQuerySb.Append($"execute procedure insertintoreview('{model.ReviewedDate}',{model.Price},{model.MotorcycleDataId},'{model.ReviewHeader}',{model.ContributionCount},{model.MonthCount},'{model.InsuranceAgency}','{model.EndDate}');");

            CommandExecuter.CommandExecuter.ExecuteNonQuery(InsertIntoReviewQuerySb.ToString());
        }
Ejemplo n.º 6
0
        public async Task Create(CreateReviewInputModel model)
        {
            if (this.User.Identity.IsAuthenticated)
            {
                var user = await this.userManager.GetUserAsync(this.User);

                model.KeepFitUserId = user.Id;
            }

            await this.reviewsService.CreateAsync(model);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Add(int id, CreateReviewInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            await this.reviewsService.CreateAsync(id, user.Id, input.Text);

            return(this.RedirectToAction("All", "Reviews", new { id = id }));
        }
        public async Task UpdateSeasonReviewShouldUpdateReviewProperly()
        {
            var user1 = new MovieDatabaseUser
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                AvatarLink = "avatar",
            };
            var season1 = new Season
            {
                SeasonNumber     = 1,
                Episodes         = 10,
                LengthPerEpisode = 29,
                ReleaseDate      = DateTime.Parse("28 October 2016"),
            };
            var seasonReview1 = new SeasonReview
            {
                Season  = season1,
                User    = user1,
                Content = "content1",
                Rating  = 8,
                Date    = DateTime.Parse("27 July 2019"),
            };
            await dbContext.Seasons.AddAsync(season1);

            await dbContext.SeasonReviews.AddAsync(seasonReview1);

            await dbContext.SaveChangesAsync();

            var seasonId = season1.Id;
            var userId   = user1.Id;

            var reviewService = new ReviewService(dbContext, mapper);

            var input = new CreateReviewInputModel
            {
                Id      = seasonId,
                Content = "content2",
                Rating  = 7,
            };

            var actualResult = await reviewService.UpdateSeasonReviewAsync(userId, input);

            Assert.True(actualResult);
            Assert.True(dbContext.SeasonReviews.Count() == 1);

            Assert.Equal(7, dbContext.SeasonReviews.First().Rating);
            Assert.Equal("content2", dbContext.SeasonReviews.First().Content);
            Assert.Equal(userId, dbContext.SeasonReviews.First().UserId);
            Assert.Equal(seasonId, dbContext.SeasonReviews.First().SeasonId);
        }
        public async Task CreateAsync(CreateReviewInputModel createReviewInputModel)
        {
            var review = new Review
            {
                Title       = createReviewInputModel.Title,
                RecipeId    = createReviewInputModel.RecipeId,
                UserId      = createReviewInputModel.UserId,
                Description = createReviewInputModel.Content,
                Rate        = createReviewInputModel.Rate,
            };

            var doesExist = await this.reviewsRepository
                            .All()
                            .Where(x => x.UserId == createReviewInputModel.UserId && x.RecipeId == createReviewInputModel.RecipeId)
                            .AnyAsync();

            if (doesExist)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.ReviewAlreadyExists, review.Id));
            }
            else
            {
                await this.reviewsRepository.AddAsync(review);

                await this.reviewsRepository.SaveChangesAsync();

                var reviews = this.reviewsRepository
                              .All()
                              .Where(o => o.RecipeId == createReviewInputModel.RecipeId)
                              .ToList();
                var reviewsCount  = reviews.Count;
                var oldrecipeRate = 0;

                foreach (var currReview in reviews)
                {
                    oldrecipeRate += currReview.Rate;
                }

                var newrating = oldrecipeRate / reviewsCount;

                var newrecipe = await this.recipesRepository
                                .All()
                                .FirstOrDefaultAsync(x => x.Id == createReviewInputModel.RecipeId);

                newrecipe.Rate = newrating;

                this.recipesRepository.Update(newrecipe);
                await this.reviewsRepository.SaveChangesAsync();
            }
        }
        public async Task GetSeasonReviewShouldReturnCorrectModel()
        {
            var user1 = new MovieDatabaseUser
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                AvatarLink = "avatar",
            };
            var season1 = new Season
            {
                SeasonNumber     = 1,
                Episodes         = 10,
                LengthPerEpisode = 29,
                ReleaseDate      = DateTime.Parse("28 October 2016"),
            };
            var seasonReview1 = new SeasonReview
            {
                Season  = season1,
                User    = user1,
                Content = "content1",
                Rating  = 8,
                Date    = DateTime.Parse("27 July 2019"),
            };
            await dbContext.Seasons.AddAsync(season1);

            await dbContext.SeasonReviews.AddAsync(seasonReview1);

            await dbContext.SaveChangesAsync();

            var seasonId = season1.Id;
            var userId   = user1.Id;

            var reviewService = new ReviewService(dbContext, mapper);

            var expectedResult = new CreateReviewInputModel
            {
                Id      = seasonId,
                Content = "content1",
                Rating  = 8,
            };

            var actualResult = await reviewService.GetSeasonReviewAsync(userId, seasonId);

            Assert.Equal(expectedResult.GetType(), actualResult.GetType());
            Assert.Equal(expectedResult.Id, actualResult.Id);
            Assert.Equal(expectedResult.Content, actualResult.Content);
            Assert.Equal(expectedResult.Rating, actualResult.Rating);
        }
Ejemplo n.º 11
0
        public async Task <int> CreateAsync(CreateReviewInputModel model)
        {
            var product = await this.productsService.GetProductByIdAsync <ProductViewModel>(model.ProductId);

            if (product == null)
            {
                throw new ProductNotFoundException(string.Format(ExceptionMessages.ProductNotFound, model.ProductId));
            }

            var review = this.mapper.Map <Review>(model);

            this.context.Reviews.Add(review);
            var rowsAdded = await this.context.SaveChangesAsync();

            return(rowsAdded);
        }
Ejemplo n.º 12
0
        public async Task <bool> CreateMovieReviewAsync(string userId, CreateReviewInputModel input)
        {
            if (await dbContext.MovieReviews.AnyAsync(movieReview => movieReview.MovieId == input.Id && movieReview.UserId == userId))
            {
                return(false);
            }

            var movieReviewForDb = mapper.Map <CreateReviewInputModel, MovieReview>(input);

            movieReviewForDb.UserId = userId;

            await dbContext.MovieReviews.AddAsync(movieReviewForDb);

            await dbContext.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 13
0
        public async Task <bool> UpdateSeasonReviewAsync(string userId, CreateReviewInputModel input)
        {
            if (!await dbContext.SeasonReviews.AnyAsync(seasonReview => seasonReview.SeasonId == input.Id && seasonReview.UserId == userId))
            {
                return(false);
            }

            var seasonReviewFromDb = await dbContext.SeasonReviews
                                     .SingleOrDefaultAsync(seasonReview => seasonReview.SeasonId == input.Id && seasonReview.UserId == userId);

            seasonReviewFromDb.Content = input.Content;
            seasonReviewFromDb.Rating  = input.Rating;
            seasonReviewFromDb.Date    = DateTime.UtcNow;

            await dbContext.SaveChangesAsync();

            return(true);
        }
        public async Task CheckIfCreateAsyncThrowsExceptionForDuplicate()
        {
            this.SeedDatabase();

            var review = new CreateReviewInputModel()
            {
                Title    = this.firstReview.Title,
                Rate     = this.firstReview.Rate,
                Content  = this.firstReview.Description,
                RecipeId = this.firstReview.RecipeId,
                UserId   = this.firstReview.UserId,
            };

            var exception = await Assert.ThrowsAsync <ArgumentException>(
                async() => await this.reviewService.CreateAsync(review));

            Assert.NotNull(exception);
        }
        public async Task CheckIfCreateAsyncWorksCorrectly()
        {
            this.SeedDatabase();

            var review = new CreateReviewInputModel()
            {
                Title    = this.firstReview.Title,
                Rate     = this.firstReview.Rate,
                Content  = this.firstReview.Description,
                RecipeId = 1,
                UserId   = "2",
            };

            await this.reviewService.CreateAsync(review);

            var result = await this.reviewsRepository.All().CountAsync();

            Assert.Equal(2, result);
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Update(CreateReviewInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(View(input));
            }

            string userId = await userService.GetUserIdFromUserNameAsync(User.Identity.Name);

            bool idIsValidMovieOrSeasonId = await reviewService.IsValidMovieOrSeasonIdAsync(input.Id);

            bool reviewExists = await reviewService.ReviewExistsAsync(userId, input.Id);

            if (!(idIsValidMovieOrSeasonId && reviewExists))
            {
                return(Redirect(GlobalConstants.redirectError));
            }

            var itemType = await reviewService.IsIdMovieOrSeasonIdAsync(input.Id);

            if (itemType == GlobalConstants.Movie)
            {
                if (!await reviewService.UpdateMovieReviewAsync(userId, input))
                {
                    return(Redirect(GlobalConstants.redirectError));
                }

                return(Redirect(redirectMovieDetails + input.Id));
            }
            else if (itemType == GlobalConstants.Season)
            {
                if (!await reviewService.UpdateSeasonReviewAsync(userId, input))
                {
                    return(Redirect(GlobalConstants.redirectError));
                }

                return(Redirect(redirectSeasonDetails + input.Id));
            }
            else
            {
                return(Redirect(GlobalConstants.redirectError));
            }
        }
Ejemplo n.º 17
0
        public ActionResult CreateFor(CreateReviewInputModel data)
        {
            var movie = _movieRepository.Find(data.MovieID);

            if (!CanReviewerReviewGenre(movie.Genres))
            {
                return View("InvalidGenre", PrepareInvalidGenreViewModel(movie.Genres));
            }

            var review = new Review
            {
                MovieID = data.MovieID,
                Comment = data.Comment,
                Stars = data.Stars,
                ReviewDate = DateTime.Now,
                UserID = _currentUser.Username
            };
            _reviewRepository.InsertOrUpdate(review);
            _reviewRepository.Save();
            return RedirectToAction("View", new { id = review.ID });
        }
Ejemplo n.º 18
0
        public async Task CreateAnonymousReview_ShouldCreateAndReturnCount()
        {
            this.Initialize();

            var input = new CreateReviewInputModel()
            {
                Title       = Title,
                Content     = Content,
                GivenRating = GivenRating,
                ProductId   = ProductId
            };

            var expectedCount = 1;
            var actual        = await this.service.CreateAsync(input);

            Assert.Equal(expectedCount, actual);
            Assert.Equal(expectedCount, this.context.Reviews.Count());
            await this.service.CreateAsync(input);

            Assert.Equal(2, this.context.Reviews.Count());
        }
        public async Task UpdateSeasonReviewShouldReturnFalseIfReviewDoesntExist()
        {
            var user1 = new MovieDatabaseUser
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                AvatarLink = "avatar",
            };
            var season1 = new Season
            {
                SeasonNumber     = 1,
                Episodes         = 10,
                LengthPerEpisode = 29,
                ReleaseDate      = DateTime.Parse("28 October 2016"),
            };

            await dbContext.Seasons.AddAsync(season1);

            await dbContext.SaveChangesAsync();

            var seasonId = season1.Id;
            var userId   = user1.Id;

            var reviewService = new ReviewService(dbContext, mapper);

            var input = new CreateReviewInputModel
            {
                Id      = seasonId,
                Content = "content1",
                Rating  = 8,
            };

            var actualResult = await reviewService.UpdateSeasonReviewAsync(userId, input);

            Assert.False(actualResult);
            Assert.True(dbContext.SeasonReviews.Count() == 0);
        }
Ejemplo n.º 20
0
        public async Task <ActionResult <SuccessViewModel <ReviewViewModel> > > Post([FromRoute] string productId, [FromBody] CreateReviewInputModel model)
        {
            if (!this._productsService.Exists(productId))
            {
                return(BadRequest(new BadRequestViewModel
                {
                    Message = "Product not found."
                }));
            }

            try
            {
                var creator = await this._userManager.FindByNameAsync(this.User.Identity.Name);

                var review = await this._reviewsService.CreateAsync(model.Review, creator.Id, productId);

                return(new SuccessViewModel <ReviewViewModel>
                {
                    Message = "Review added successfully.",
                    Data = this._mapper.Map <ReviewViewModel>(review)
                });
            }
            catch (Exception)
            {
                return(BadRequest(new BadRequestViewModel
                {
                    Message = "Something went wrong."
                }));
            }
        }
Ejemplo n.º 21
0
        private async void AddReviewButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(ReviewPriceTextBox.Text) || !IsMoney(ReviewPriceTextBox.Text))
                {
                    MessageBox.Show("Няма цена.");
                    return;
                }

                if (string.IsNullOrEmpty(MounthsCombo.Text))
                {
                    MessageBox.Show("Избери месеци");
                    return;
                }

                short contributionsCount = GetContributionsCount();

                if (contributionsCount == -1)
                {
                    MessageBox.Show("Избери Вноски");
                    return;
                }
                if (string.IsNullOrEmpty(InsuranceAngecyCombo.Text))
                {
                    MessageBox.Show("Попълнете застрахователна агенция!");
                    return;
                }
                if (InsuranceAngecyCombo.Text.Length > 60)
                {
                    MessageBox.Show("Твърде дълго име на застрахователна ангеция!");
                    return;
                }

                short mounthsCount = short.Parse(MounthsCombo.Text);

                CreateReviewInputModel createReviewModel = new CreateReviewInputModel
                {
                    ContributionCount = contributionsCount,
                    MonthCount        = mounthsCount,
                    Price             = double.Parse(ReviewPriceTextBox.Text),
                    ReviewedDate      = ReviewStartDate.Value.ToString("dd.MM.yyyy"),
                    ReviewHeader      = reviewService.GenerateReviewHeader(ReviewStartDate.Value),
                    MotorcycleDataId  = GlobalVariables.CurrentBikeId,
                    InsuranceAgency   = InsuranceAngecyCombo.Text,
                    EndDate           = reviewService.GenerateEndDate(ReviewStartDate.Value, mounthsCount).ToString("dd.MM.yyyy"),
                };

                reviewService.CreateReview(createReviewModel);

                await Information("Успешно добавена нова застраховка", InformationType.Success);

                GenerateContributionInfo(createReviewModel);
                ClearReviewFileds();
            }
            catch (Exception ex)
            {
                logger.LogExceptionText(ex.ToString(), "Batkooo sefte pisha neshto v tiq raboti eiiiiiii mainaaaaaaa");
                await Information("Нещо се обърка. Няма добавена застраховка", InformationType.Error);
            }
        }