Exemple #1
0
        public int GetInvoicesCount(
            String searchText,
            InvoiceStatus?status,
            DateTime issueDateFrom,
            DateTime issueDateTo,
            DateTime dueDateFrom,
            DateTime dueDateTo,
            EntityType entityType,
            int entityID,
            String currency)
        {
            var cacheKey = TenantID.ToString(CultureInfo.InvariantCulture) +
                           "invoice" +
                           _securityContext.CurrentAccount.ID.ToString() +
                           searchText;

            var fromCache = _cache.Get <string>(cacheKey);

            if (fromCache != null)
            {
                return(Convert.ToInt32(fromCache));
            }

            var withParams = hasParams(searchText, status, issueDateFrom, issueDateTo, dueDateFrom, dueDateTo, entityType, entityID, currency);

            var exceptIDs = _crmSecurity.GetPrivateItems(typeof(Invoice)).ToList();

            int result;

            if (withParams)
            {
                var sqlQuery = GetDbInvoceByFilters(exceptIDs, searchText, status, issueDateFrom, issueDateTo, dueDateFrom, dueDateTo, entityType, entityID, currency);

                result = sqlQuery != null?sqlQuery.Count() : 0;
            }
            else
            {
                var countWithoutPrivate = Query(CrmDbContext.Invoices).Count();

                var privateCount = exceptIDs.Count;

                if (privateCount > countWithoutPrivate)
                {
                    _logger.ErrorFormat(@"Private invoice count more than all cases. Tenant: {0}. CurrentAccount: {1}",
                                        TenantID,
                                        _securityContext.CurrentAccount.ID);

                    privateCount = 0;
                }

                result = countWithoutPrivate - privateCount;
            }

            if (result > 0)
            {
                _cache.Insert(cacheKey, result.ToString(), TimeSpan.FromSeconds(30));
            }
            return(result);
        }
Exemple #2
0
        public int GetDealsCount(String searchText,
                                 Guid responsibleID,
                                 int milestoneID,
                                 IEnumerable <String> tags,
                                 int contactID,
                                 DealMilestoneStatus?stageType,
                                 bool?contactAlsoIsParticipant,
                                 DateTime fromDate,
                                 DateTime toDate)
        {
            var cacheKey = TenantID.ToString(CultureInfo.InvariantCulture) +
                           "deals" +
                           _securityContext.CurrentAccount.ID.ToString() +
                           searchText +
                           responsibleID +
                           milestoneID +
                           contactID;

            if (tags != null)
            {
                cacheKey += String.Join("", tags.ToArray());
            }

            if (stageType.HasValue)
            {
                cacheKey += stageType.Value;
            }

            if (contactAlsoIsParticipant.HasValue)
            {
                cacheKey += contactAlsoIsParticipant.Value;
            }

            if (fromDate != DateTime.MinValue)
            {
                cacheKey += fromDate.ToString();
            }

            if (toDate != DateTime.MinValue)
            {
                cacheKey += toDate.ToString();
            }

            var fromCache = _cache.Get <string>(cacheKey);

            if (fromCache != null)
            {
                return(Convert.ToInt32(fromCache));
            }

            var withParams = !(String.IsNullOrEmpty(searchText) &&
                               responsibleID == Guid.Empty &&
                               milestoneID <= 0 &&
                               (tags == null || !tags.Any()) &&
                               contactID <= 0 &&
                               stageType == null &&
                               contactAlsoIsParticipant == null &&
                               fromDate == DateTime.MinValue &&
                               toDate == DateTime.MinValue);

            ICollection <int> exceptIDs = _crmSecurity.GetPrivateItems(typeof(Deal)).ToList();

            int result;

            if (withParams)
            {
                var sqlQuery = GetDbDealByFilters(exceptIDs, searchText, responsibleID, milestoneID, tags,
                                                  contactID, stageType, contactAlsoIsParticipant,
                                                  fromDate,
                                                  toDate, null);

                if (sqlQuery == null)
                {
                    result = 0;
                }
                else
                {
                    result = sqlQuery.Count();
                }
            }
            else
            {
                var countWithoutPrivate = Query(CrmDbContext.Deals).Count();
                var privateCount        = exceptIDs.Count;

                if (privateCount > countWithoutPrivate)
                {
                    _logger.Error("Private deals count more than all deals");

                    privateCount = 0;
                }

                result = countWithoutPrivate - privateCount;
            }
            if (result > 0)
            {
                _cache.Insert(cacheKey, result.ToString(), TimeSpan.FromSeconds(30));
            }

            return(result);
        }
Exemple #3
0
        public int GetCasesCount(
            String searchText,
            int contactID,
            bool?isClosed,
            IEnumerable <String> tags)
        {
            var cacheKey = TenantID.ToString(CultureInfo.InvariantCulture) +
                           "cases" +
                           _securityContext.CurrentAccount.ID.ToString() +
                           searchText +
                           contactID;

            if (tags != null)
            {
                cacheKey += String.Join("", tags.ToArray());
            }

            if (isClosed.HasValue)
            {
                cacheKey += isClosed.Value;
            }

            var fromCache = _cache.Get <string>(cacheKey);

            if (fromCache != null)
            {
                return(Convert.ToInt32(fromCache));
            }


            var withParams = !(String.IsNullOrEmpty(searchText) &&
                               contactID <= 0 &&
                               isClosed == null &&
                               (tags == null || !tags.Any()));


            var exceptIDs = _crmSecurity.GetPrivateItems(typeof(Cases)).ToList();

            int result;

            if (withParams)
            {
                var dbCasesQuery = GetDbCasesByFilters(exceptIDs, searchText, contactID, isClosed, tags);

                result = dbCasesQuery != null?dbCasesQuery.Count() : 0;
            }
            else
            {
                var countWithoutPrivate = Query(CrmDbContext.Cases).Count();

                var privateCount = exceptIDs.Count;

                if (privateCount > countWithoutPrivate)
                {
                    _logger.ErrorFormat(@"Private cases count more than all cases. Tenant: {0}. CurrentAccount: {1}",
                                        TenantID,
                                        _securityContext.CurrentAccount.ID);
                    privateCount = 0;
                }

                result = countWithoutPrivate - privateCount;
            }

            if (result > 0)
            {
                _cache.Insert(cacheKey, result.ToString(), TimeSpan.FromSeconds(30));
            }

            return(result);
        }