Esempio n. 1
0
        private async Task CheckForBlockDocument(Guid documentId, DocumentDenounceEnum denounceMotivation)
        {
            const int maxDenouncesNumberTotal         = 25;
            const int maxDenouncesNumberInMonth       = 10;
            const int maxDenouncesNumberInLast48Hours = 4;
            var       numberOfDenouncesTotal          = await Repository
                                                        .Where(d => d.DocumentId == documentId)
                                                        .Where(d => d.DenounceMotivation == denounceMotivation)
                                                        .CountAsync();

            var numberOfDenouncesInMonth = await Repository
                                           .Where(d => d.DocumentId == documentId)
                                           .Where(d => d.DenounceMotivation == denounceMotivation)
                                           .Where(d => d.DenounceTime > DateTime.Now.AddDays(-30))
                                           .CountAsync();

            var numberOfDenouncesInLast48Hours = await Repository
                                                 .Where(d => d.DocumentId == documentId)
                                                 .Where(d => d.DenounceMotivation == denounceMotivation)
                                                 .Where(d => d.DenounceTime > DateTime.Now.AddDays(-2))
                                                 .CountAsync();

            if (
                numberOfDenouncesTotal >= maxDenouncesNumberTotal ||
                numberOfDenouncesInMonth > maxDenouncesNumberInMonth ||
                numberOfDenouncesInLast48Hours > maxDenouncesNumberInLast48Hours
                )
            {
                await BlockDocument(documentId);
            }
        }
Esempio n. 2
0
        private async Task <bool> HasUserAlreadyDenounce(Guid documentId, DocumentDenounceEnum denounceMotivation, Guid userId)
        {
            if (userId == Guid.Empty)
            {
                return(false);
            }

            return(await Repository
                   .Where(d => d.DocumentId == documentId)
                   .Where(d => d.DenounceMotivation == denounceMotivation)
                   .Where(d => d.UserId == userId)
                   .AnyAsync());
        }