Exemplo n.º 1
0
        public void GetReviewsByPostTests()
        {
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            applicationDbContext = new ApplicationDbContext(builder.Options, _configuration);
            repository           = new Repository <Review>(applicationDbContext);
            reviewService        = new ReviewService(repository);
            Post post = new Post()
            {
                Id = Guid.Parse("b7db8ddd-6637-4321-8a8f-9899e1ba99aa"), Title = "Title", Content = "Content"
            };

            applicationDbContext.Posts.Add(post);
            for (int i = 0; i < 10; i++)
            {
                applicationDbContext.Reviews.Add(new Review()
                {
                    Id = Guid.NewGuid(), Post = post
                });
            }
            applicationDbContext.SaveChanges();
            var reports = reviewService.GetAll(post);

            Assert.NotNull(reports);
            Assert.Equal(10, reports.Count());
            for (int i = 0; i < reports.Count(); i++)
            {
                Assert.Equal(post, reports.ToArray()[i].Post);
            }
        }
Exemplo n.º 2
0
        public void GetReviewsByUserTests()
        {
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            applicationDbContext = new ApplicationDbContext(builder.Options, _configuration);
            repository           = new Repository <Review>(applicationDbContext);
            reviewService        = new ReviewService(repository);
            var user = UserHelpers.AddUser(applicationDbContext);

            for (int i = 0; i < 10; i++)
            {
                applicationDbContext.Reviews.Add(new Review()
                {
                    Id = Guid.NewGuid(), User = user
                });
            }
            applicationDbContext.SaveChanges();
            var reports = reviewService.GetAll(user);

            Assert.NotNull(reports);
            Assert.Equal(10, reports.Count());
            for (int i = 0; i < reports.Count(); i++)
            {
                Assert.Equal(user, reports.ToArray()[i].User);
            }
        }
Exemplo n.º 3
0
        public IActionResult GetSpecialistProfile()
        {
            var user = UserService.Get(long.Parse(User.Identity.Name));

            if (user == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Пользователь не найден"
                }));
            }

            var specialist = SpecialistService.GetSpecialistFromUser(user);

            if (specialist == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Специалист не найден"
                }));
            }

            var reviews = ReviewService.GetAll()
                          .Where(x => x.Session.Specialist == specialist)
                          .OrderByDescending(x => x.Session.Date)
                          .Select(x => new ReviewViewModel(x))
                          .ToList();

            var sessions = SessionService.GetSpecialistSessions(specialist)
                           .Where(x => x.IsClientClose && x.IsSpecialistClose)
                           .ToList();

            var clients = new HashSet <User>();

            sessions.ForEach(session => clients.Add(session.Problem.User));

            var profile = new SpecialistProfileViewModel
            {
                SpecialistID         = specialist.ID,
                FirstName            = user.FirstName,
                LastName             = user.LastName,
                Rating               = ReviewService.GetSpecialistRating(specialist),
                PositiveReviewsCount = reviews.Where(x => x.Score > 3).Count(),
                NeutralReviewsCount  = reviews.Where(x => x.Score == 3).Count(),
                NegativeReviewsCount = reviews.Where(x => x.Score < 3).Count(),
                PhotoUrl             = specialist.User.Photo != null ? specialist.User.Photo.Url : null,
                Price         = specialist.Price,
                TotalEarnings = sessions.Where(x => x.Status == SessionStatus.Success).Sum(x => x.Reward),
                TotalSessions = sessions.Count,
                TotalClients  = clients.Count
            };

            return(Ok(new DataResponse <SpecialistProfileViewModel>
            {
                Data = profile
            }));
        }
Exemplo n.º 4
0
        void PrintAll()
        {
            IEnumerable <Review> reviewCollection = reviewService.GetAll();

            foreach (var item in reviewCollection)
            {
                Console.WriteLine(item.MovieId + "\t" + item.UserId + "\t" + item.Rating + "\t" + item.ReviewText);
            }
        }
        public ActionResult AllReviews()
        {
            try
            {
                var reviews = reviewService.GetAll();

                return(View(new GetAllReviewsViewModel {
                    Reviews = reviews
                }));
            }
            catch (EntityNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception)
            {
                return(BadRequest("Invalid request received"));
            }
        }
Exemplo n.º 6
0
        public static List <Review> GetAll()
        {
            var apiCallTask = ReviewService.GetAll();
            var result      = apiCallTask.Result;

            JArray        jsonResponse = JsonConvert.DeserializeObject <JArray>(result);
            List <Review> reviewsList  = JsonConvert.DeserializeObject <List <Review> >(jsonResponse.ToString());

            return(reviewsList);
        }
Exemplo n.º 7
0
        private SpecialistViewModel GetFullSpecialist(Specialist specialist)
        {
            var reviews = ReviewService.GetAll()
                          .Where(x => x.Session.Specialist == specialist)
                          .Select(x => new ReviewViewModel(x))
                          .ToList();

            var rating = ReviewService.GetSpecialistRating(specialist);

            return(new SpecialistViewModel(specialist, rating, reviews));
        }
Exemplo n.º 8
0
        public IActionResult Index()
        {
            var reviews       = rev.GetAll();
            var listingResult = reviews.Select(result => new ReviewViewModel {
                Id = result.Id, comment = result.comment, rating = result.rating
            });

            var model = new ReviewIndexModel()
            {
                Reviews = listingResult
            };

            return(View(model));
        }
Exemplo n.º 9
0
        public void ReviewServiceTest_GetAll()
        {
            // Arange
            var reviewService = new ReviewService(_mockRepository.Object);

            _mockRepository.Setup(reviewRepository => reviewRepository.GetAll())
            .Returns(_reviewList);

            // Act
            var reviews = reviewService.GetAll();

            // Assert
            Assert.IsNotNull(reviews);
            Assert.AreEqual(2, reviews.Count());
        }
Exemplo n.º 10
0
        public void ReviewServiceTest_GetAll()
        {
            // Arange
            var reviewService = new ReviewService(_mockRepository.Object);

            _mockRepository.Setup(reviewRepository => reviewRepository.GetAll())
                .Returns(_reviewList);

            // Act
            var reviews = reviewService.GetAll();

            // Assert
            Assert.IsNotNull(reviews);
            Assert.AreEqual(2, reviews.Count());
        }
Exemplo n.º 11
0
        public void GetReviewsTests()
        {
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            applicationDbContext = new ApplicationDbContext(builder.Options, _configuration);
            repository           = new Repository <Review>(applicationDbContext);
            reviewService        = new ReviewService(repository);
            for (int i = 0; i < 10; i++)
            {
                applicationDbContext.Reviews.Add(new Review()
                {
                    Id = Guid.NewGuid()
                });
            }
            applicationDbContext.SaveChanges();
            var review = reviewService.GetAll();

            Assert.NotNull(review);
            Assert.Equal(10, review.Count());
        }
        public ActionResult YourAuthorsView()
        {
            try
            {
                var authors = authorService.GetAll();
                var reviews = reviewService.GetAll();
                ICollection <Review> ReviewsByUser = new Collection <Review>();
                ICollection <Author> AuthorsByUser = new Collection <Author>();

                var userEmail = userManager.GetUserName(User);
                var user      = userService.GetUserByUserEmail(userEmail);

                foreach (var item in reviews)
                {
                    if (item.User == user)
                    {
                        ReviewsByUser.Add(item);
                    }
                }

                foreach (var item in authors)
                {
                    if (item.User == user)
                    {
                        AuthorsByUser.Add(item);
                    }
                }

                return(View(new YourAuthorsViewModel {
                    Reviews = ReviewsByUser, Authors = AuthorsByUser
                }));
            }
            catch (EntityNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception)
            {
                return(BadRequest("Invalid request received"));
            }
        }
Exemplo n.º 13
0
        public ActionResult DashboardView()
        {
            try
            {
                var reviews  = reviewService.GetAll();
                var comments = commentService.GetAll();

                ICollection <Review> ReviewsByUser = new Collection <Review>();

                var userEmail = userManager.GetUserName(User);
                var user      = userService.GetUserByUserEmail(userEmail);
                var followers = userService.GetUser_Followers(user);
                foreach (var item in reviews)
                {
                    foreach (var item1 in followers)
                    {
                        if (item.User == item1.User)
                        {
                            ReviewsByUser.Add(item);
                        }
                    }
                }


                return(View(new DashboardViewModel {
                    Reviews = ReviewsByUser, Comments = comments
                }));
            }
            catch (EntityNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception)
            {
                return(BadRequest("Invalid request received"));
            }
        }
Exemplo n.º 14
0
 // GET: Review
 public async Task <IActionResult> Index()
 {
     return(View(await _reviewService.GetAll()));
 }