コード例 #1
0
ファイル: ReviewController.cs プロジェクト: navff/mhbb-back
        public async Task <IHttpActionResult> Get(int id)
        {
            try
            {
                var review = await _reviewOperations.GetAsync(id);

                if (review == null)
                {
                    return(this.Result404("This review is not found"));
                }
                var result = Mapper.Map <ReviewViewModelGet>(review);

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

                return(Ok(result));
            }
            catch (Exception ex)
            {
                ErrorLogger.Log("CANNOT GET REVIEW", ex);
                throw;
            }
        }
コード例 #2
0
        public void Get_Ok_Test()
        {
            var review = _context.Reviews.Include(r => r.User).First();
            var result = _reviewOperations.GetAsync(review.Id).Result;

            Assert.AreEqual(review.Text, result.Text);
            Assert.AreEqual(review.User.Name, review.User.Name);
        }