Exemplo n.º 1
0
        public async Task <IActionResult> UpdateReviewQuestions([FromRoute] int id, [FromBody] int[] chosenIds)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var review = _context.Reviews.AsNoTracking().Where(x => x.Id == id).Include(x => x.ProblemHierarchies).Include(x => x.Chapters).ThenInclude(c => c.Questions).FirstOrDefault(m => m.Id == id);

            if (review == null)
            {
                return(BadRequest(ModelState));
            }

            IList <int> list       = chosenIds.ToList();
            var         questions  = _context.TestungQuestions.Where(x => list.IndexOf(x.Id.Value) >= 0).ToList();
            var         chapterIds = _context.TestungQuestions.Where(x => list.IndexOf(x.Id.Value) >= 0).Select(c => c.TestungChapterId).Distinct();
            var         chapters   = _context.TestungChapters.Where(x => chapterIds.IndexOf(x.Id.Value) >= 0).ToList();

            _bl.addReviewTests(review, chapters, _context);

            var reviewUpdated = _context.Reviews.AsNoTracking().Where(x => x.Id == id).Include(x => x.ProblemHierarchies).Include(x => x.Chapters).ThenInclude(c => c.Questions).FirstOrDefault(m => m.Id == id);

            return(Ok(reviewUpdated));
        }