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)); }
public override Result Apply(IEnumerable <int> ids) { var query = _quizQuestionRepository.AsNoTracking.Where(q => ids.Contains(q.Id)); var result = new Result().SetSuccess(string.Format(Messages.RecordInactivate, query.Count())); foreach (var entity in query) { entity.IsActive = false; _quizQuestionRepository.Update(entity); } _unitOfWork.Commit(); QuizQuestionCacheManager.ClearCache(); return(result); }