Ejemplo n.º 1
0
        public async Task <IActionResult> DeleteAllCodedAnswersFromCodedQuestion([FromBody] CleanupCodedQuestionDto dto)
        {
            if (dto == null)
            {
                return(BadRequest());
            }

            await deleteCodedAnswersFromCodedQuestion(dto);

            return(await _unitOfWork.Complete() <= 0 ? StatusCode(500) : NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DeleteCodedQuestion([FromBody] CleanupCodedQuestionDto dto)
        {
            if (dto == null)
            {
                return(BadRequest());
            }

            //Must delete coded answers first
            await deleteCodedAnswersFromCodedQuestion(dto);

            if (dto.Categories.Count > 0)
            {
                foreach (var categoryId in dto.Categories)
                {
                    var codedCategoryQuestion = await _unitOfWork.CodedCategoryQuestions
                                                .SingleOrDefaultAsync(ccq =>
                                                                      ccq.Id == dto.UserId &&
                                                                      ccq.ProjectJurisdiction.Id == dto.ProjectJurisdictionId &&
                                                                      ccq.SchemeQuestionId == dto.SchemeQuestionId &&
                                                                      ccq.Category.Id == categoryId);

                    if (codedCategoryQuestion != null)
                    {
                        _unitOfWork.CodedCategoryQuestions.Remove(codedCategoryQuestion);
                    }
                }
            }
            else
            {
                var codedQuestion = await _unitOfWork.CodedQuestions
                                    .SingleOrDefaultAsync(cq =>
                                                          cq.CodedBy.Id == dto.UserId &&
                                                          cq.ProjectJurisdiction.Id == dto.ProjectJurisdictionId &&
                                                          cq.SchemeQuestionId == dto.SchemeQuestionId);

                if (codedQuestion != null)
                {
                    _unitOfWork.CodedQuestions.Remove(codedQuestion);
                }
            }

            return(await _unitOfWork.Complete() <= 0 ? StatusCode(500) : NoContent());
        }
Ejemplo n.º 3
0
        private async Task <bool> deleteCodedAnswersFromCodedQuestion(CleanupCodedQuestionDto dto)
        {
            if (dto.Categories.Count > 0)
            {
                foreach (var categoryId in dto.Categories)
                {
                    var ccq = await _unitOfWork.CodedCategoryQuestions
                              .SingleOrDefaultAsync(cq =>
                                                    cq.CodedBy.Id == dto.UserId &&
                                                    cq.ProjectJurisdiction.Id == dto.ProjectJurisdictionId &&
                                                    cq.SchemeQuestionId == dto.SchemeQuestionId &&
                                                    cq.Category.Id == categoryId);

                    if (ccq?.CodedAnswers?.Count <= 0)
                    {
                        return(false);
                    }

                    _unitOfWork.CodedAnswers.RemoveRange(ccq.CodedAnswers);
                }
            }
            else
            {
                var codedQuestion = await _unitOfWork.CodedQuestions
                                    .SingleOrDefaultAsync(
                    cq => cq.CodedBy.Id == dto.UserId &&
                    cq.ProjectJurisdiction.Id == dto.ProjectJurisdictionId &&
                    cq.SchemeQuestionId == dto.SchemeQuestionId);

                if (codedQuestion?.CodedAnswers?.Count <= 0)
                {
                    return(false);
                }

                _unitOfWork.CodedAnswers.RemoveRange(codedQuestion.CodedAnswers);
            }

            return(true);
        }