示例#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();
        }
示例#2
0
        //public Dictionary<Tag, int> GetTagCloud(int quantity)
        //{
        //    var parameters = new SqlParameter[] { new SqlParameter("@Quantity", quantity.ToString())};
        //    var tags1 = _repository.FromSql(new TagCloud() , @"SELECT TOP (CONVERT(INT,@Quantity)) Id, QuestionId, TagId
        //                                           ,COUNT(0) Count  FROM[dbo].[QuestionTag]  GROUP BY Id, QuestionId, TagId  ORDER BY COUNT(0) DESC", parameters);

        //    var tags = _repository.GetTagCloud();
        //    //.GroupBy(info => info.Tag)
        //    //.Select(group => new {
        //    //    Tag = group.Key,
        //    //    Count = group.Count()
        //    //})
        //    //.OrderByDescending(x => x.Count)
        //    //.Take(quantity)
        //    //.ToDictionary(x => x.Tag, x=>x.Count);

        //    var tagg = tags.Select(c => new
        //    {
        //        c.Tag
        //    }).GroupBy(c => c.Tag, (k, g) => new
        //    {
        //        Tag = k,
        //        Count = g.Count()
        //    }).OrderByDescending(x => x.Count).Take(quantity);

        //    return tagg.ToDictionary(x => x.Tag, x => x.Count);
        //}

        public void Remove(QuestionTag obj)
        {
            _repository.Remove(obj);
        }