public bool ChangeReviewStatus(string identity, int topicId, TopicReviewStatus status)
 {
     try
     {
         var user = GetUserByIdentity(identity);
         if (!DbContext.TopicReviews.Any(rs => rs.TopicId == topicId && rs.ReviewerId == user.Id))
         {
             var review = new TopicReview()
             {
                 TopicId    = topicId,
                 ReviewerId = user.Id,
                 Status     = status.Status
             };
             DbContext.TopicReviews.Add(review);
         }
         else
         {
             var review =
                 DbContext.TopicReviews.Include(r => r.Reviewer)
                 .Single(rs => rs.TopicId == topicId && rs.ReviewerId == user.Id);
             review.Status = status.Status;
             DbContext.Update(review);
         }
         DbContext.SaveChanges();
         return(true);
     }
     catch (InvalidOperationException)
     {
         return(false);
     }
 }
Exemplo n.º 2
0
 public TopicsControllerReviewsTest()
 {
     _tester           = new ControllerTester <TopicsController>();
     TopicReviewStatus = new TopicReviewStatus {
         Status = "Reviewed"
     };
     TopicReview = new TopicReview
     {
         TopicId    = _tester.TopicOne.Id,
         ReviewerId = _tester.Reviewer.Id,
         Status     = "InReview"
     };
 }
Exemplo n.º 3
0
        public IActionResult PutReviewStatus([FromRoute] int topicId, [FromBody] TopicReviewStatus status)
        {
            if (!_topicPermissions.IsReviewer(User.Identity.GetUserId(), topicId))
            {
                return(Forbidden());
            }
            if (!ModelState.IsValid || !status.IsStatusValid())
            {
                return(BadRequest());
            }
            if (!_topicManager.IsValidTopicId(topicId))
            {
                return(NotFound());
            }

            if (_topicManager.ChangeReviewStatus(User.Identity.GetUserId(), topicId, status))
            {
                return(Ok());
            }

            return(BadRequest());
        }