public Result Edit(int id, QuizAnswerEditAdminDto dto)
        {
            dto.Id = id;
            var result = _validatorEdit.ValidateResult(dto);

            if (!result.Success)
            {
                return(result);
            }

            if (dto.Id > 0)
            {
                var entity = _quizAnswerRepository.AsNoTracking.FirstOrDefault(w => w.Id == dto.Id);

                if (entity == null)
                {
                    return(result.SetError("There are error for update record. Please try again with refresh."));
                }
                var query = _quizAnswerRepository.AsNoTracking.Where(x => x.QuizQuestionId == entity.QuizQuestionId);

                if (dto.IsCorrectAnswer)
                {
                    query.Update(u => new QuizAnswer {
                        IsCorrectAnswer = false
                    });
                }

                Mapper.Map <QuizAnswer>(dto, entity);
                _quizAnswerRepository.Update(entity);
                _unitOfWork.Commit();

                result.Id = entity.Id;
            }
            else
            {
                var entity = Mapper.Map <QuizAnswer>(dto);
                _quizAnswerRepository.Insert(entity);
                _unitOfWork.Commit();

                result.Id = entity.Id;
            }

            QuizAnswerCacheManager.ClearCache();

            return(result.SetSuccess(Messages.RecordSaved));
        }
        public void SaveSortOrder(int[] ids)
        {
            var entities = _quizAnswerRepository.AsNoTracking
                           .Where(w => ids.Contains(w.Id))
                           .ToList();

            for (var index = 0; index < ids.Length; index++)
            {
                var id        = ids[index];
                var sortOrder = index + 1;
                entities.Where(w => w.Id == id).ForEach(ac => ac.SortOrder = sortOrder);
            }

            _quizAnswerRepository.Update(entities);
            _unitOfWork.Commit();

            QuizAnswerCacheManager.ClearCache();
        }
        public Result Create(QuizAnswerCreateAdminDto dto)
        {
            var result = _validatorCreate.ValidateResult(dto);

            if (!result.Success)
            {
                return(result);
            }

            var entity = Mapper.Map <QuizAnswer>(dto);

            _quizAnswerRepository.Insert(entity);
            _unitOfWork.Commit();

            QuizAnswerCacheManager.ClearCache();

            result.Id = entity.Id;

            return(result.SetSuccess(Messages.RecordSaved));
        }