예제 #1
0
        public void SaveSortOrder(int[] ids)
        {
            var entities = _quizQuestionRepository.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);
            }

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

            QuizQuestionCacheManager.ClearCache();
        }
예제 #2
0
        public Result Edit(int id, QuizQuestionEditAdminDto dto)
        {
            dto.Id = id;
            var result = _validatorEdit.ValidateResult(dto);

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

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

                if (entity == null)
                {
                    return(result.SetError("There are error for update record. Please try again with refresh."));
                }

                Mapper.Map <QuizQuestion>(dto, entity);
                _quizQuestionRepository.Update(entity);

                _unitOfWork.Commit();

                result.Id = entity.Id;
            }
            else
            {
                var entity = Mapper.Map <QuizQuestion>(dto);
                _quizQuestionRepository.Insert(entity);

                _unitOfWork.Commit();

                result.Id = entity.Id;
            }

            QuizQuestionCacheManager.ClearCache();

            return(result.SetSuccess(Messages.RecordSaved));
        }
예제 #3
0
        public Result Create(QuizQuestionCreateAdminDto dto)
        {
            var result = _validatorCreate.ValidateResult(dto);

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

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

            entity.IsActive = true;

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

            QuizQuestionCacheManager.ClearCache();

            result.Id = entity.Id;

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