Exemplo n.º 1
0
        public void GetByUserEmail_Ok_Test()
        {
            var review = _context.Reviews.Include(r => r.User).First();
            var result = _reviewOperations.GetByUserEmailAsync(review.User.Email).Result;

            Assert.IsTrue(result.Any());
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> GetByUser(string email)
        {
            try
            {
                var reviews = await _reviewOperations.GetByUserEmailAsync(email);

                var result = new List <ReviewViewModelGet>();
                foreach (var review in reviews)
                {
                    var viewModel = Mapper.Map <ReviewViewModelGet>(review);
                    viewModel.ActivityName = review.Activity.Name;

                    var picture          = (await _pictureOperations.GetByLinkedObject(LinkedObjectType.User, viewModel.User.Id)).FirstOrDefault();
                    var pictureViewModel = Mapper.Map <PictureViewModelGet>(picture);
                    if (pictureViewModel != null)
                    {
                        pictureViewModel.Url   = Url.Content($"~/api/picture/{pictureViewModel.Id}");
                        viewModel.User.Picture = pictureViewModel;
                    }

                    result.Add(viewModel);
                }
                return(Ok(result));
            }
            catch (Exception ex)
            {
                ErrorLogger.Log("CANNOT GET REVIEWS", ex);
                throw;
            }
        }
Exemplo n.º 3
0
        public async Task DeleteAsync(string email)
        {
            var user = _context.Users.FirstOrDefault(u => u.Email == email);

            Contracts.Assert(user != null);

            var reviews = await _reviewsOperations.GetByUserEmailAsync(user.Email);

            foreach (var review in reviews)
            {
                await _reviewsOperations.DeleteAsync(review.Id);
            }
            var userVoices = await _voiceOperations.GetUserVoices(user.Id);

            foreach (var userVoice in userVoices)
            {
                await _voiceOperations.DeleteVoiceAsync(userVoice.Id);
            }

            _context.Users.Remove(user);
            await _context.SaveChangesAsync();
        }