Example #1
0
        public async Task ApplyAsync(int paymentUseId)
        {
            var paymentUse = await _context.PaymentUses
                             .Include(pu => pu.PaymentInvoice)
                             .ThenInclude(pi => pi.Request)
                             .ThenInclude(r => r.Documents)
                             .ThenInclude(rd => rd.Document)
                             .ThenInclude(d => d.Type)
                             .Include(pu => pu.PaymentInvoice)
                             .ThenInclude(pi => pi.Request)
                             .ThenInclude(r => r.ProtectionDocType)
                             .Include(pu => pu.PaymentInvoice)
                             .ThenInclude(pi => pi.Request)
                             .ThenInclude(r => r.CurrentWorkflow)
                             .ThenInclude(cw => cw.CurrentStage)
                             .Include(pu => pu.PaymentInvoice)
                             .ThenInclude(pi => pi.Request)
                             .ThenInclude(r => r.CurrentWorkflow)
                             .ThenInclude(cw => cw.FromStage)
                             .Include(pu => pu.PaymentInvoice)
                             .ThenInclude(pi => pi.Request)
                             .ThenInclude(r => r.Documents)
                             .ThenInclude(rd => rd.Document)
                             .ThenInclude(d => d.Type)
                             .Include(pu => pu.PaymentInvoice)
                             .ThenInclude(pi => pi.Request)
                             .ThenInclude(r => r.PaymentInvoices)
                             .ThenInclude(pi => pi.Tariff)
                             .Include(pu => pu.PaymentInvoice).ThenInclude(pi => pi.Tariff)
                             .Include(pu => pu.PaymentInvoice).ThenInclude(pi => pi.Status)
                             .SingleOrDefaultAsync(p => p.Id == paymentUseId);

            if (paymentUse.PaymentInvoice.Status.Code.Equals("notpaid"))
            {
                return;
            }

            var request = paymentUse.PaymentInvoice.Request;

            if (request == null)
            {
                throw new ApplicationException($"Payment with id: {paymentUse.PaymentId} hasn't request");
            }

            var logic = _logicFactory.Create(paymentUse.PaymentInvoice.Request.ProtectionDocType.Code);

            if (logic != null)
            {
                await logic.ApplyAsync(paymentUse);
            }

            await _context.SaveChangesAsync();
        }
Example #2
0
        public async Task ApplyAsync(params int[] documentsIds)
        {
            var requestDocuments = await _context.RequestsDocuments
                                   .Include(rd => rd.Request).ThenInclude(r => r.Workflows).ThenInclude(w => w.CurrentStage)
                                   .Include(rd => rd.Request).ThenInclude(r => r.ProtectionDocType)
                                   .Include(rd => rd.Request).ThenInclude(r => r.Documents).ThenInclude(rd => rd.Document).ThenInclude(d => d.Type)
                                   .Include(rd => rd.Request).ThenInclude(r => r.CurrentWorkflow).ThenInclude(cw => cw.CurrentStage)
                                   .Include(rd => rd.Request).ThenInclude(r => r.CurrentWorkflow).ThenInclude(cw => cw.FromStage)
                                   .Include(rd => rd.Request).ThenInclude(r => r.PaymentInvoices).ThenInclude(pi => pi.Tariff)
                                   .Include(rd => rd.Request).ThenInclude(r => r.PaymentInvoices).ThenInclude(pi => pi.Status)
                                   .Include(rd => rd.Document).ThenInclude(d => d.Type)
                                   .Where(rd => documentsIds.Contains(rd.DocumentId))
                                   .ToListAsync();

            var tasks = requestDocuments
                        .Select(rd => _logicFactory.Create(rd.Request.ProtectionDocType.Code)?.ApplyAsync(rd) ?? Task.CompletedTask)
                        .ToArray();

            Task.WaitAll(tasks);

            await _context.SaveChangesAsync();
        }
Example #3
0
        public async Task ApplyAsync(int userId, params int[] documentsIds)
        {
            var user = _context.Users
                       .Include(u => u.Position)
                       .Single(u => u.Id == userId);

            var requestDocuments = await _context.RequestsDocuments
                                   .Include(rd => rd.Request).ThenInclude(r => r.ProtectionDocType)
                                   .Include(rd => rd.Request).ThenInclude(r => r.CurrentWorkflow).ThenInclude(r => r.CurrentStage)
                                   .Include(rd => rd.Request).ThenInclude(r => r.CurrentWorkflow).ThenInclude(r => r.FromStage)
                                   .Include(rd => rd.Document).ThenInclude(d => d.Type)
                                   .Where(rd => documentsIds.Contains(rd.DocumentId))
                                   .ToListAsync();

            var tasks = requestDocuments
                        .Select(rd => _logicFactory.Create(rd.Request.ProtectionDocType.Code)?.ApplyAsync(user, rd) ?? Task.CompletedTask)
                        .ToArray();

            Task.WaitAll(tasks);

            await _context.SaveChangesAsync();
        }
Example #4
0
 public StreamingSubscriber(ILogicFactory logicFactory)
 {
     _logic = logicFactory.Create(this);
 }