Beispiel #1
0
        public void UpdateQuestion(QuestionDto question, string operatedBy)
        {
            var entity = _questionRepository.Get(question.Id);

            if (entity == null)
            {
                throw new AppServiceException("No object found.");
            }

            entity.Remark    = string.IsNullOrEmpty(question.Remark) ? entity.Remark : question.Remark;
            entity.Subject   = string.IsNullOrEmpty(question.Subject) ? entity.Subject : question.Subject;
            entity.UpdatedBy = operatedBy;
            entity.UpdatedOn = DateTime.Now;

            var entityTags = _questionTagRepository.GetFiltered(o => o.QuestionId == question.Id).ToList();

            if (entityTags != null && entityTags.Any())
            {
                foreach (var item in entityTags)
                {
                    _questionTagRepository.Remove(item);
                }
            }
            IEnumerable <QuestionTagDto> tags = question.Tags ?? new List <QuestionTagDto>();

            foreach (var item in tags)
            {
                var tag = QuestionTagFactory.CreateInstance(item.Name, question.Id);
                _questionTagRepository.Add(tag);
            }
            _questionRepository.Update(entity);
            _dbUnitOfWork.Commit();
        }
Beispiel #2
0
        public void AddQuestion(QuestionDto question, string operatedBy)
        {
            var entity = QuestionFactory.CreateInstance(question.Subject, question.Remark, operatedBy);

            _questionRepository.Add(entity);
            var tags = question.Tags;

            foreach (var item in tags)
            {
                var tag = QuestionTagFactory.CreateInstance(item.Name, entity.Id);
                _questionTagRepository.Add(tag);
            }
            _dbUnitOfWork.Commit();
        }