コード例 #1
0
        private async Task <IEnumerable <RevenueBySite> > RevenueByAllSites <RType>(ResolveFieldContext context, QueryTemplate <RType> query, DateTime date) where RType : IRevenue
        {
            if (context.ThrowIfInvalidAuthorization() == false)
            {
                return(null);
            }
            var sitekeys = context.GetAllSiteIds();
            List <RevenueBySite> results = new List <RevenueBySite>();

            using (IStatelessSession session = mysqlDataAccessor.SessionFactory.OpenStatelessSession())
            {
                foreach (int site in sitekeys)
                {
                    var result = await query(session, date, new int[] { site });

                    RevenueBySite line = new RevenueBySite {
                        siteid = site, sumofmoney = result.Sum(x => x.Revenue)
                    };
                    results.Add(line);
                }
            }
            return(results.OrderByDescending(x => x.sumofmoney));
        }
コード例 #2
0
        private async Task <RevenueBySite> RevenueSitesBysite <RType>(ResolveFieldContext context, QueryTemplate <RType> query, DateTime date, int site) where RType : IRevenue
        {
            if (context.ThrowIfInvalidAuthorization() == false)
            {
                return(null);
            }
            var siteKeys = context.GetAllSiteIds();

            if (siteKeys.Contains(site) == false)
            {
                context.Errors.Add(new GraphQL.ExecutionError("대상 사이트는 소유하지 않았습니다"));
                return(null);
            }
            using (IStatelessSession session = mysqlDataAccessor.SessionFactory.OpenStatelessSession())
            {
                var result = await query(session, date, new int[] { site });

                RevenueBySite line = new RevenueBySite {
                    siteid = site, sumofmoney = result.Sum(x => x.Revenue)
                };
                return(line);
            }
        }