public StudentsGDP()
        {
            InitializeComponent();
            IRatingRepository ratingRepository = new RatingRepository();

            this.ratingBusiness = new RatingBusiness(ratingRepository);
        }
        private async Task <Option <Rating, Error> > RateAsync(RateRestaurant command)
        {
            var result = await RatingRepository
                         .GetByUserIdAndRestaurantIdAsync(command.UserId, command.RestaurantId);

            try
            {
                // CREATE
                if (result == default)
                {
                    var entry  = Mapper.Map <Rating>(command);
                    var rating = await RatingRepository.SaveAsync(entry);

                    return(rating.Some <Rating, Error>());
                }

                // UPDATE
                result.Stars = command.Stars;
                await RatingRepository.UpdateAsync(result);

                return(result.Some <Rating, Error>());
            }
            catch (Exception ex)
            {
                Debug.Fail($"Un error has accrued: {ex.Message}");
                return(Option.None <Rating, Error>(
                           Error.Critical("Something happens while saving the rating of the restaurant!")));
            }
        }
Exemple #3
0
    public async Task <Rating> SetStarAsync(CmsUser user, string entityType, string entityId, short starCount)
    {
        var currentUserRating = await RatingRepository.GetCurrentUserRatingAsync(entityType, entityId, user.Id);

        if (currentUserRating != null)
        {
            currentUserRating.SetStarCount(starCount);

            return(await RatingRepository.UpdateAsync(currentUserRating));
        }

        if (!await RatingDefinitionStore.IsDefinedAsync(entityType))
        {
            throw new EntityCantHaveRatingException(entityType);
        }

        return(await RatingRepository.InsertAsync(
                   new Rating(
                       GuidGenerator.Create(),
                       entityType,
                       entityId,
                       starCount,
                       user.Id,
                       CurrentTenant.Id
                       )
                   ));
    }
Exemple #4
0
 public void DeleteRating(int ratingId)
 {
     //unitOfWork.StartTransaction();
     RatingRepository repo = new RatingRepository(unitOfWork);
     repo.Delete(x => x.RatingId == ratingId);
     //unitOfWork.Commit();
 }
Exemple #5
0
        public void TestGetNumberOfReviewsFromReviewer()
        {
            IRatingRepository _rtngRepo    = new RatingRepository(true);
            double            actualResult = _rtngRepo.GetNumberOfReviewsFromReviewer(1);

            Assert.AreEqual(2, actualResult);
        }
Exemple #6
0
        public virtual async Task <RatingDto> CreateAsync(string entityType, string entityId,
                                                          CreateUpdateRatingInput input)
        {
            var userId = CurrentUser.GetId();
            var user   = await CmsUserLookupService.GetByIdAsync(userId);

            var currentUserRating = await RatingRepository.GetCurrentUserRatingAsync(entityType, entityId, userId);

            if (currentUserRating != null)
            {
                currentUserRating.SetStarCount(input.StarCount);
                var updatedRating = await RatingRepository.UpdateAsync(currentUserRating);

                return(ObjectMapper.Map <Rating, RatingDto>(updatedRating));
            }

            var rating = await RatingRepository.InsertAsync(
                new Rating(
                    GuidGenerator.Create(),
                    entityType,
                    entityId,
                    input.StarCount,
                    user.Id,
                    CurrentTenant.Id
                    )
                );

            return(ObjectMapper.Map <Rating, RatingDto>(rating));
        }
Exemple #7
0
        private void RefreshRating()
        {
            VoteResults vr = RatingRepository.GetVoteResults(this.ItemKey);

            positiveRates = vr.Positive;
            negativeRates = vr.Negative;
        }
Exemple #8
0
        public void TestGetAverageRateFromReviewer()
        {
            IRatingRepository _rtngRepo    = new RatingRepository(true);
            double            actualResult = _rtngRepo.GetAverageRateFromReviewer(1);

            Assert.AreEqual(5.5, actualResult);
        }
Exemple #9
0
            public async Task ReturnsViewWithMovieViewModel()
            {
                //Arrange
                const string movieUrl     = "https://test.test/api/film/1";
                const string title        = "Test movie title";
                const string openingCrawl = "lorem ipsum";
                var          scores       = new[] { 7, 4 };

                var movie = new Movie
                {
                    Url          = movieUrl,
                    OpeningCrawl = openingCrawl,
                    Title        = title
                };
                var ratings = scores.Select(s => new Rating
                {
                    Id       = Guid.NewGuid(),
                    MovieUrl = movieUrl,
                    Score    = s
                }).ToList();

                RatingRepository.GetAll(movieUrl).Returns(ratings);
                MoviesService.GetMovie(movieUrl).Returns(movie);

                //Act
                var result = await HomeController.Details(movieUrl);

                //Assert
                var viewResult = Assert.IsType <ViewResult>(result);
                var model      = Assert.IsAssignableFrom <MovieViewModel>(viewResult.ViewData.Model);

                Assert.Equal(movie.Title, model.Title);
                Assert.True(model.Scores.SequenceEqual(scores));
                Assert.Equal(title, model.Title);
            }
Exemple #10
0
        public void TestGetAverageRateOfMovie()
        {
            IRatingRepository _rtngRepo    = new RatingRepository(true);
            double            actualresult = _rtngRepo.GetAverageRateOfMovie(1998);

            Assert.AreEqual(9, actualresult);
        }
Exemple #11
0
        public void TestGetNumberOfRates()
        {
            IRatingRepository _rtngRepo    = new RatingRepository(true);
            double            actualresult = _rtngRepo.GetNumberOfRates(1994, 7);

            Assert.AreEqual(1, actualresult);
        }
        public async Task RatingRepo_GetAll_ReturnsAllElementsWithCorrectType()
        {
            var repository = new RatingRepository(_context);
            var result     = await repository.GetAllAsync();

            Assert.IsAssignableFrom <IEnumerable <Rating> >(result);
        }
        public void Init()
        {
            _userRepository           = new UserRepository();
            _commonPlacesRepository   = new CommonPlacesRepository();
            _missionRepository        = new MissionRepository();
            _missionSetRepository     = new MissionSetRepository();
            _missionRequestRepository = new MissionRequestRepository();
            _appCountersRepository    = new AppCountersRepository();
            _hintRequestRepository    = new HintRequestRepository();
            _ratingRepository         = new RatingRepository();
            var imageProvider = new ImageProvider();

            _imageService          = new ImageService(imageProvider, _userRepository);
            _ratingService         = new RatingService(_userRepository, _ratingRepository, true);
            _appCountersService    = new AppCountersService(_appCountersRepository);
            _service               = new UserService(_userRepository, _missionRepository, _ratingRepository, _appCountersService);
            _missionService        = new MissionService(_missionRepository, _userRepository, _missionSetRepository, _missionRequestRepository, _hintRequestRepository, _ratingService, _commonPlacesRepository);
            _missionRequestService = new MissionRequestService(_missionRequestRepository, _missionRepository, _userRepository, _commonPlacesRepository,
                                                               _ratingService, new NotificationService(new NotificationProvider()), _appCountersService);

            var principal = new ClaimsPrincipal();

            principal.AddIdentity(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Sid, "User1Id") }));
            _controller = new MissionController(_missionService, _missionRequestService, _imageService)
            {
                User = principal
            };
        }
Exemple #14
0
        public RatingDboTest()
        {
            repository = new RatingRepository(DbContextFactory);
            dataService = new RatingDataService(repository, UnitOfWork);

            userRepository = new UserRepository(DbContextFactory);
            productRepository = new ProductRepository(DbContextFactory);
        }
Exemple #15
0
        public virtual async Task <RatingDto> GetCurrentUserRatingAsync(string entityType, string entityId)
        {
            var currentUserId = CurrentUser.GetId();

            var rating = await RatingRepository.GetCurrentUserRatingAsync(entityType, entityId, currentUserId);

            return(ObjectMapper.Map <Rating, RatingDto>(rating));
        }
Exemple #16
0
 public HomeController()
 {
     authContext = new ApplicationDbContext();
     manualRepository = new ManualRepository(new ApplicationDbContext());
     categoryRepository = new CategoryRepository(new ApplicationDbContext());
     tagRepository = new TagRepository(new ApplicationDbContext());
     ratingRepository = new RatingRepository(new ApplicationDbContext());
 }
        public async void ExistRatings()
        {
            RatingRepository ratingRepository = new RatingRepository(_dataContext);

            var result = await ratingRepository.GetAllRatings();

            Assert.True(result.Length > 0);
        }
Exemple #18
0
        public RatingDboTest()
        {
            repository  = new RatingRepository(DbContextFactory);
            dataService = new RatingDataService(repository, UnitOfWork);

            userRepository    = new UserRepository(DbContextFactory);
            productRepository = new ProductRepository(DbContextFactory);
        }
 public BaseController()
 {
     UserRep         = new UserProfileRepository();
     VideoRep        = new VideoTableRepository();
     VideoCommentRep = new VideoCommentRepository();
     LikeTableRep    = new LikeTableRepository();
     RateTableRep    = new RatingRepository();
 }
Exemple #20
0
        public void TestGetReviewersByMovie()
        {
            IRatingRepository _rtngRepo     = new RatingRepository(true);
            List <int>        actualresult  = _rtngRepo.GetReviewersByMovie(1994);
            List <int>        reviewersList = new List <int>();

            reviewersList.Add(2);
            CollectionAssert.AreEqual(reviewersList, actualresult);
        }
        /// <summary>
        /// Randomized the list of possible matches so that we don't have the possibilities returned in the same order everytime
        /// </summary>
        /// <returns></returns>
        public static List <Tuple <Cat, Cat> > CatsToCompare()
        {
            var cats = RatingRepository.GetCats();

            //Randomized the list of the possible matches
            var list = Generator.GenerateAllPossibilities <Cat>(cats).Randomize();

            return(list);
        }
        public async Task RatingRepo_GetAll_ReturnsAllFiveSeededElements()
        {
            var repository = new RatingRepository(_context);
            var result     = await repository.GetAllAsync();

            int expectedCount = 3;

            Assert.Equal(expectedCount, result.Count());
        }
Exemple #23
0
 public HomeController()
 {
     authContext         = new ApplicationDbContext();
     manualRepository    = new ManualRepository(new ApplicationDbContext());
     categoryRepository  = new CategoryRepository(new ApplicationDbContext());
     tagRepository       = new TagRepository(new ApplicationDbContext());
     ratingRepository    = new RatingRepository(new ApplicationDbContext());
     templatesRepository = new TemplatesRepository(new ApplicationDbContext());
     userRepository      = new UserRepository(new ApplicationDbContext());
 }
Exemple #24
0
        public void TestGetMostProductiveReviewers()
        {
            IRatingRepository _rtngRepo      = new RatingRepository(true);
            List <int>        actualresult   = _rtngRepo.GetMostProductiveReviewers();
            List <int>        expectedresult = new List <int>();

            expectedresult.Add(1);
            expectedresult.Add(2);
            CollectionAssert.AreEqual(expectedresult, actualresult);
        }
Exemple #25
0
        public MovieFormViewModel()
        {
            GenreRepository    genreRepo  = new GenreRepository();
            LocationRepository locaRepo   = new LocationRepository();
            RatingRepository   ratingRepo = new RatingRepository();

            Genres    = new SelectList(genreRepo.GetAllGenres(), "genre_id", "genre_name");
            Locations = new SelectList(locaRepo.GetAllLocations(), "location_id", "location_name");
            Ratings   = new SelectList(ratingRepo.GetAllRatings(), "rating_id", "rating_name");
        }
Exemple #26
0
 public RoleController(RoleManager <IdentityRole> roleManager, UserManager <ApplicationUser> userManager, ApplicationContext context)
 {
     FanficRepository          = new FanficRepository(context);
     CommentRepository         = new CommentRepository(context);
     RatingRepository          = new RatingRepository(context);
     LikeRepository            = new LikeRepository(context);
     ApplicationUserRepository = new ApplicationUserRepository(context);
     _roleManager = roleManager;
     _userManager = userManager;
 }
Exemple #27
0
        public void TestGetTopMoviesByReviewer()
        {
            IRatingRepository _rtngRepo      = new RatingRepository(true);
            List <int>        actualresult   = _rtngRepo.GetTopMoviesByReviewer(1);
            List <int>        expectedresult = new List <int>();

            expectedresult.Add(1998);
            expectedresult.Add(1997);
            CollectionAssert.AreEqual(expectedresult, actualresult);
        }
Exemple #28
0
        public UnitOfWork(AdvertContext context)
        {
            this.context = context;

            CommentRepository    = new CommentRepository(context);
            RatingRepository     = new RatingRepository(context);
            RealEstateRepository = new RealEstateRepository(context);
            UserRepository       = new UserRepository(context);
            PictureRepository    = new PictureRepository(context);
        }
        public virtual async Task DeleteAsync(string entityType, string entityId)
        {
            var rating = await RatingRepository.GetCurrentUserRatingAsync(entityType, entityId, CurrentUser.GetId());

            if (rating.CreatorId != CurrentUser.GetId())
            {
                throw new AbpAuthorizationException();
            }

            await RatingRepository.DeleteAsync(rating.Id);
        }
Exemple #30
0
 public UnitOfWork(ANDbContext context)
 {
     _context  = context;
     Animes    = new AnimeRepository(_context);
     Favorites = new FavoriteRepository(_context);
     Forums    = new ForumRepository(_context);
     Messages  = new MessageRepository(_context);
     Genres    = new GenreRepository(_context);
     Ratings   = new RatingRepository(_context);
     Studios   = new StudioRepository(_context);
 }
Exemple #31
0
        public RatingsForm()
        {
            InitializeComponent();
            IRatingRepository  ratingRepository  = new RatingRepository();
            IStudentRepository studentRepository = new StudentRepository();
            ICourseRepository  courseRepository  = new CourseRepository();

            this.ratingBusiness  = new RatingBusiness(ratingRepository);
            this.studentBusiness = new StudentBusiness(studentRepository);
            this.courseBusiness  = new CourseBusiness(courseRepository);
        }
Exemple #32
0
 public UnitOfWork(ApplicationDbContext db)
 {
     _db             = db;
     Genre           = new GenreRepository(_db);
     Rating          = new RatingRepository(_db);
     GameObj         = new GameRepository(_db);
     ApplicationUser = new ApplicationUserRepository(_db);
     ShoppingCart    = new ShoppingCartRepository(_db);
     OrderDetails    = new OrderDetailsRepository(_db);
     OrderHeader     = new OrderHeaderRepository(_db);
 }
Exemple #33
0
        public void TestGetMoviesWithHighestNumberOfTopRates()
        {
            IRatingRepository _rtngRepo      = new RatingRepository(true);
            List <int>        actualresult   = _rtngRepo.GetMoviesWithHighestNumberOfTopRates();
            List <int>        expectedresult = new List <int>();

            expectedresult.Add(1997);
            expectedresult.Add(1994);
            expectedresult.Add(1998);
            CollectionAssert.AreEqual(expectedresult, actualresult);
        }
Exemple #34
0
 public RatingModel GetRatingByJobId(int JobId)
 {
     //unitOfWork.StartTransaction();
     RatingRepository repo = new RatingRepository(unitOfWork);
     RatingModel ratingModel = new RatingModel();
     Rating rating = new Rating();
     AutoMapper.Mapper.Map(ratingModel, rating);
     rating = repo.GetAll().Where(x => x.JobId == JobId).FirstOrDefault();
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(rating, ratingModel);
     return ratingModel;
 }
Exemple #35
0
 public List<RatingModel> GetAllRatings()
 {
     //unitOfWork.StartTransaction();
     RatingRepository repo = new RatingRepository(unitOfWork);
     List<RatingModel> ratingModelList = new List<RatingModel>();
     List<Rating> rating = new List<Rating>();
     AutoMapper.Mapper.Map(ratingModelList, rating);
     rating = repo.GetAll().ToList();
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(rating, ratingModelList);
     return ratingModelList;
 }
Exemple #36
0
 public RatingModel GetRatingByServiceProviderId(string ServiceProviderId)
 {
     //unitOfWork.StartTransaction();
     RatingRepository repo = new RatingRepository(unitOfWork);
     RatingModel ratingModel = new RatingModel();
     Rating rating = new Rating();
     AutoMapper.Mapper.Map(ratingModel, rating);
     //rating = repo.GetAll().Where(x => x. == ServiceProviderId).FirstOrDefault();
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(rating, ratingModel);
     return ratingModel;
 }
Exemple #37
0
 public RatingController()
 {
     ratingRepo = new RatingRepository();
 }
Exemple #38
0
 public RatingModel UpadteRating(RatingModel model)
 {
     //unitOfWork.StartTransaction();
     RatingRepository repo = new RatingRepository(unitOfWork);
     Rating rating = new Rating();
     rating = repo.GetAll().Where(x => x.RatingId == model.RatingId).FirstOrDefault();
     AutoMapper.Mapper.Map(model, rating);
     repo.Update(rating);
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(rating, model);
     return model;
 }
Exemple #39
0
 public List<RatingModel> GetRatingListByjobIds(string[] jobIds)
 {
     //unitOfWork.StartTransaction();
     RatingRepository repo = new RatingRepository(unitOfWork);
     List<RatingModel> ratingModelList = new List<RatingModel>();
     List<Rating> ratingList = new List<Rating>();
     AutoMapper.Mapper.Map(ratingModelList, ratingList);
     ratingList = repo.GetAll().Where(x => jobIds.Contains(x.JobId.ToString())).ToList();
     //unitOfWork.Commit();
     //ratingList = repo.GetAll().Where(x => x.JobId == jobid).ToList();
     AutoMapper.Mapper.Map(ratingList, ratingModelList);
     return ratingModelList;
 }
Exemple #40
0
 public List<RatingModel> GetRatingListByServiceProviderId(int jobid)
 {
     //unitOfWork.StartTransaction();
     RatingRepository repo = new RatingRepository(unitOfWork);
     List<RatingModel> ratingModelList = new List<RatingModel>();
     List<Rating> ratingList = new List<Rating>();
     AutoMapper.Mapper.Map(ratingModelList, ratingList);
     ratingList = repo.GetAll().Where(x => x.JobId == jobid).ToList();
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(ratingList, ratingModelList);
     return ratingModelList;
 }
Exemple #41
0
 public RatingModel SaveRating(RatingModel model)
 {
     //unitOfWork.StartTransaction();
     RatingRepository repo = new RatingRepository(unitOfWork);
     Rating rating = new Rating();
     AutoMapper.Mapper.Map(model, rating);
     repo.Insert(rating);
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(rating, model);
     return model;
 }
Exemple #42
0
 public List<RatingModel> GetRatingListByJobId(int JobId)
 {
     //unitOfWork.StartTransaction();
     RatingRepository repo = new RatingRepository(unitOfWork);
     List<RatingModel> ratingModel = new List<RatingModel>();
     List<Rating> rating = new List<Rating>();
     AutoMapper.Mapper.Map(ratingModel, rating);
     rating = repo.GetAll().Where(x => x.JobId == JobId).ToList();
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(rating, ratingModel);
     return ratingModel;
 }