public async Task <IActionResult> ProcessQuestion([FromBody] ProcessQuestionModel model)
        {
            try
            {
                var result = await questionLib.ProcessQuestionAsync(model, CurrentUserId);

                return(CustomResult(result));
            }
            catch (System.Exception exp)
            {
                return(CustomError(exp));
            }
        }
Exemple #2
0
        public async Task <bool> ProcessQuestionAsync(ProcessQuestionModel model, long userId)
        {
            var entity = await questionRepo.FirstAsync(x =>
                                                       x.Id == model.Id &&
                                                       x.Box.UserId == userId &&
                                                       x.IsPending);

            if (entity == null)
            {
                throw new Exception("Item Not Found!");
            }

            entity.IsPending = false;

            if (model.IsSuccess)
            {
                if (entity.MainStage == 5)
                {
                    entity.IsFinished = true;
                }
                else
                {
                    entity.QuestionHistory.Add(new QuestionHistory
                    {
                        FromMainStage     = entity.MainStage,
                        FromSubStage      = entity.SubStage,
                        HistoryActionType = HistoryActionType.Success,
                        ToMainStage       = ++entity.MainStage,
                        ToSubStage        = entity.SubStage = 1
                    });
                }
            }
            else
            {
                entity.FailCount++;
                entity.QuestionHistory.Add(new QuestionHistory
                {
                    FromMainStage     = entity.MainStage,
                    FromSubStage      = entity.SubStage,
                    HistoryActionType = HistoryActionType.Fail,
                    ToMainStage       = entity.MainStage = 1,
                    ToSubStage        = entity.SubStage = 1
                });
            }

            await unitOfWork.CommitAsync();

            return(true);
        }