public OffersSelectedCategoryStats(int categoryId, int userId, int webApiUserWebsiteCategoryId)
 {
     webApiUserWebsiteCategory = new WebApiUserWebsiteCategory(webApiUserWebsiteCategoryId);
     PaidPlan                  = new PaidPlan(webApiUserWebsiteCategory.PaidPlanId);
     IndexedDocumentCount      = ElasticController.Instance.GetIndexDocumentCount(categoryId, userId);
     IndexedDocumentThisMonth  = ElasticController.Instance.GetIndexDocumentCountThisMonth(categoryId, userId);
     IncomeForStorageThisMonth =
         CalculatePriceController.GetStoragePrice(IndexedDocumentCount, webApiUserWebsiteCategory.PaidPlanId);
     IncomeForProceedOffersThisMonth =
         CalculatePriceController.GetProceedPrice(IndexedDocumentThisMonth,
                                                  webApiUserWebsiteCategory.PaidPlanId);
     IncomeThisMonth =
         CalculatePriceController.GetPrice(IndexedDocumentThisMonth, IndexedDocumentCount, webApiUserWebsiteCategory.PaidPlanId);
     FoundMappings = ElasticController.Instance.GetIndexMappings(categoryId, userId);
 }
        public List <FetchingProcessedOffersRow> GetOffers(int userId)
        {
            List <FetchingProcessedOffersRow> ret = new List <FetchingProcessedOffersRow>();

            using (Dal db = new Dal())
            {
                using (DbDataReader reader = db.ExecuteReader($@"
                    WITH notProcessed (offerId) as (
	                    SELECT offers.Id as offerId FROM offers where WebApiUserId = {userId} AND Processed = 0
                    ),
                    processed (offerId) as (
	                    SELECT offers.Id as offerId FROM offers where WebApiUserId = {userId} AND Processed <> 0
                    )
                    select offers.WebsiteCategoryId,
                    offers.WebApiUserId,
                    COUNT(notProcessed.offerId) as NotProcessedOffers,
                    COUNT(processed.offerId) as ProcessedOffers,
                    ISNULL(websiteCategories.name,''),
                    PaidPlan.Id
                    FROM WebApiUserWebsiteCategory
                    INNER JOIN offers on offers.WebApiUserId = WebApiUserWebsiteCategory.WebApiUserId
                    LEFT JOIN notProcessed on notProcessed.offerId = offers.Id
                    LEFT JOIN processed on processed.offerId = offers.Id
                    LEFT JOIN websiteCategories ON websiteCategories.Id = offers.WebsiteCategoryId
                    LEFT JOIN PaidPlan on PaidPlan.Id = WebApiUserWebsiteCategory.PaidPlanId
                    WHERE offers.WebApiUserId = {userId}
                    group by offers.WebsiteCategoryId, OFFERS.WebApiUserId, websiteCategories.name, PaidPlan.Id
                "))
                {
                    while (reader.Read())
                    {
                        PaidPlan plan            = new PaidPlan(reader.GetInt32(5));
                        long     offersThisMonth =
                            ElasticController.Instance.GetIndexDocumentCountThisMonth(reader.GetInt32(0), userId);
                        long offersAllTime =
                            ElasticController.Instance.GetIndexDocumentCount(reader.GetInt32(0), userId);
                        ret.Add(new FetchingProcessedOffersRow()
                        {
                            CategoryId            = reader.GetInt32(0),
                            ProcessedOffersSql    = reader.GetInt32(3),
                            NotProcessedOffersSql = reader.GetInt32(2),
                            WebApiUserId          = reader.GetInt32(1),
                            CategoryName          = reader.GetString(4),
                            PaidPlan               = plan.Name,
                            OffersThisMonth        = offersThisMonth,
                            MonthPay               = Math.Round(CalculatePriceController.GetPrice(offersThisMonth, offersAllTime, reader.GetInt32(5)), 2),
                            MaxOffersInPlan        = plan.MaxOffersInDb,
                            ProcessedOffersElastic = ElasticController.Instance.GetIndexDocumentCount(reader.GetInt32(0), userId),
                            AllTimePay             = Math.Round(CalculatePriceController.GetPrice(offersThisMonth, offersAllTime, reader.GetInt32(5)), 2),
                            MaxOffersPerMonth      = plan.MaxProceedOffersInMonth
                        });
                    }
                }
            }

            foreach (var rows in ret)
            {
                rows.ProcessedOffersElastic = ElasticController.Instance.GetIndexDocumentCount(rows.CategoryId, userId);
            }

            return(ret);
        }