示例#1
0
        public SurveyResult Handle(SurveyResultQuery request)
        {
            var dateTo   = DateTime.Today.AddDays(1);
            var dateFrom = dateTo.AddDays(-request.NumberOfLastDays);

            var answersGroupedByQuestions = _queryDispatcher
                                            .Fetch(new AnswersQuery(dateFrom, dateTo))
                                            .GroupBy(n => n.QuestionKey)
                                            .ToDictionary(n => n.Key);

            var allQuestions = _queryDispatcher.Fetch(new QuestionsQuery())
                               .ToDictionary(n => n.Key);

            return(new SurveyResult
            {
                Questions = answersGroupedByQuestions.Keys
                            .Where(allQuestions.ContainsKey)
                            .Select(questionKey => new SurveyResultQuestion(allQuestions[questionKey])
                {
                    Answers = answersGroupedByQuestions[questionKey]
                              .Select(answer => new SurveyResultAnswer
                    {
                        Answer = string.Join(", ", answer.SelectedOptions)
                    })
                              .ToList()
                })
                            .ToList()
            });
        }
示例#2
0
 public ActivitiesView Handle(ActivitiesViewQuery request) => new ActivitiesView
 {
     Groups = _dispatcher
              .Fetch(new GroupsQuery())
              .Select(group => new ActivitiesViewGroup(group)
     {
         Activities = _dispatcher
                      .Fetch(new ActivitiesQuery(group.Key))
                      .Select(n => new ActivitiesViewActivity(n))
                      .ToList()
     })
              .ToList()
 };
示例#3
0
        public bool Handle(DeleteGroup request)
        {
            var cannotDelete = _disaptcher
                               .Fetch(new ActivitiesQuery(request.Key))
                               .Any();

            if (cannotDelete)
            {
                return(false);
            }

            var group = _dataStorage.Find(request.Key);

            return(_dataStorage.Delete(group));
        }
示例#4
0
            private AnnualFinancialReportMonthEntry BuildReportEntry(TaxonTree currentTaxon)
            {
                var financialJournalEntries = _dispatcher.Fetch(new FinancialJournalQuery(_thatMonth)
                {
                    Taxon = new TaxonTreeQuery
                    {
                        TaxonKey = currentTaxon.Key,
                        Deep     = currentTaxon.GetElements().Any() ? 0 : -1
                    }
                });

                var subEntries = currentTaxon.GetElements()
                                 .Select(BuildReportEntry);

                return(AnnualFinancialReportMonthEntry.Create(currentTaxon, financialJournalEntries, subEntries));
            }
示例#5
0
        public User Handle(CreateUser request)
        {
            if (request.TelegramId.HasValue)
            {
                var user = _queryDispatcher.Fetch(new FindUserByTelegramId(request.TelegramId.Value));

                if (user != null)
                {
                    throw new ArgumentException("TelegramId");
                }
            }

            return(_dataStorage.Create(new User(0)
            {
                TelegramId = request.TelegramId
            }));
        }
        public IEnumerable <FinancialJournalEntry> Handle(FinancialJournalQuery request)
        {
            var from = request.AsMonthDate();
            var to   = from.AddMonths(1);

            var rootTaxon = _dispatcher.Fetch(request.Taxon ?? new TaxonTreeQuery());

            var entries = new List <FinancialJournalEntry>();

            using (var context = GetContext())
            {
                foreach (var taxon in rootTaxon.DescendantsAndSelf())
                {
                    entries.AddRange(GetTable(context)
                                     .Where(n => n.TaxonKey == taxon.Key && from <= n.When && n.When < to)
                                     .AsEnumerable()
                                     .Select(ToEntity));
                }
            }

            return(entries);
        }
示例#7
0
 private List <TaxonTree> GetElements(int parentTaxonKey) => _dispatcher
 .Fetch(new TaxonElementsQuery(parentTaxonKey))
 .Select(n => new TaxonTree(n.Key, n.ParentKey, n.Name, n.Description))
 .ToList();