コード例 #1
0
        public async Task <IActionResult> AddNew(Tariff tariff)
        {
            _ercContext.Tariffs.Add(tariff);
            await _ercContext.SaveChangesAsync();

            return(Ok(tariff));
        }
コード例 #2
0
        public async Task <IActionResult> Add(PaymentChannel paymentChannel)
        {
            _ercContext.PaymentChannels.Add(paymentChannel);
            await _ercContext.SaveChangesAsync();

            return(Ok(paymentChannel));
        }
コード例 #3
0
        public async Task <Unit> Handle(UpdateCompanyCommand request, CancellationToken cancellationToken)
        {
            var company = await _ercContext.Company.FirstOrDefaultAsync(x => x.Id == request.Id);

            if (company is null)
            {
                throw new Exception("Company not exist");
            }

            _ercContext.Entry(company).CurrentValues.SetValues(
                new
            {
                request.Name,
                request.ShortName,
                request.DirectorName,
                request.Address,
                request.Email,
                request.Www,
                request.TaxpayerPhone,
                request.StateRegistryCode,
                request.TaxpayerNumber,
                request.BookkeeperName,
                request.BookkeeperTaxNumber
            });
            return(await _ercContext.SaveChangesAsync() > 0 ? Unit.Value : throw new Exception("Can't update company"));
        }
コード例 #4
0
        public async Task Consume(ConsumeContext <CalculateAccountingPoint> context)
        {
            if (await _ercContext.Invoices.AnyAsync(i => i.DsoConsumptionId == context.Message.Id))
            {
                return;
            }

            var ac = await _ercContext.AccountingPoints
                     .Include(ac => ac.BranchOffice.CurrentPeriod)
                     .Include(a => a.Exemptions)
                     .ThenInclude(e => e.Category)
                     .Include(a => a.TariffsHistory)
                     .ThenInclude(t => t.Tariff)
                     .FirstOrDefaultAsync(a => a.Eic == context.Message.Eic);

            if (ac is null)
            {
                throw new ArgumentOutOfRangeException("Accounting point not found in the database!");
            }

            ICalculateStrategy calculateStrategy = ac.Commodity == Commodity.NaturalGas ? _serviceProvider.GetRequiredService <GasCalculateStrategy>() : throw new NotImplementedException();

            var fromDate = context.Message.FromDate ?? ac.BranchOffice.CurrentPeriod.StartDate;
            var toDate   = context.Message.ToDate ?? ac.BranchOffice.CurrentPeriod.EndDate.AddDays(1);
            var tariff   = ac.TariffsHistory.OrderByDescending(t => t.StartDate).FirstOrDefault(t => t.StartDate <= fromDate).Tariff;

            var usageT1 = new Usage
            {
                PresentMeterReading  = context.Message.PresentMeterReadingT1,
                PreviousMeterReading = context.Message.PreviousMeterReadingT1,
                Units = context.Message.UsageT1,
            };

            var usageT2 = context.Message.UsageT2.HasValue ? new Usage
            {
                PresentMeterReading  = context.Message.PresentMeterReadingT2,
                PreviousMeterReading = context.Message.PreviousMeterReadingT2,
                Units = context.Message.UsageT2.Value,
            } : null;

            var usageT3 = context.Message.UsageT3.HasValue ? new Usage
            {
                PresentMeterReading  = context.Message.PresentMeterReadingT3,
                PreviousMeterReading = context.Message.PreviousMeterReadingT3,
                Units = context.Message.UsageT3.Value,
            } : null;

            var newInvoice = new Invoice(context.Message.Id, ac.BranchOffice.CurrentPeriodId, ac.Debt, fromDate, toDate,
                                         context.Message.MeterNumber, tariff, (ZoneRecord)context.Message.ZoneRecord, usageT1, usageT2, usageT3,
                                         type: ac.BranchOffice.CurrentPeriod.StartDate == fromDate ? InvoiceType.Common : InvoiceType.Recalculation);

            newInvoice.Calculate(calculateStrategy);
            ac.AddInvoice(newInvoice);

            await _ercContext.SaveChangesAsync();
        }
コード例 #5
0
        public async Task <Unit> Handle(UpdatePersonCommand request, CancellationToken cancellationToken)
        {
            var person = await _ercContext.People.FirstOrDefaultAsync(x => x.Id == request.Id);

            if (person is null)
            {
                throw new Exception("Person not exist");
            }

            _ercContext.Entry(person).CurrentValues.SetValues(new { request.Id, request.IdCardNumber, request.IdCardIssuanceDate, request.IdCardIssuer,
                                                                    request.IdCardExpDate, request.MobilePhones, request.Email });
            return(await _ercContext.SaveChangesAsync() > 0 ? Unit.Value : throw new Exception("Can't update person"));
        }
コード例 #6
0
        public async Task <IActionResult> Add([FromForm] NewPaymentsBatch paymentBatch)
        {
            var paymentChannel = await _mediator.Send(new GetPaymentChannelById(paymentBatch.PaymentChannelId));

            if (paymentChannel is null)
            {
                return(BadRequest("Payment channel not found!"));
            }

            var paymentList = new List <Domain.Payments.Payment>();

            if (paymentBatch.UploadFile != null)
            {
                var extFile = Path.GetExtension(paymentBatch.UploadFile.FileName);
                if (extFile == ".dbf")
                {
                    paymentList = new PaymentsDbfParser(_ercContext, _branchOfficeService).Parser(paymentBatch.BranchOfficeId, paymentChannel, paymentBatch.UploadFile);
                }
                else if (extFile == ".xls" || extFile == ".xlsx")
                {
                    return(BadRequest("Excel files not yet supported"));
                }
            }

            var payBatch = new PaymentsBatch(
                paymentBatch.BranchOfficeId,
                paymentBatch.PaymentChannelId,
                paymentBatch.IncomingDate,
                paymentList
                );

            _ercContext.PaymentBatches.Add(payBatch);
            await _ercContext.SaveChangesAsync();

            return(await GetOne(payBatch.Id));
        }
コード例 #7
0
        public async Task <Unit> Handle(UpdateBranchOfficeCommand request, CancellationToken cancellationToken)
        {
            var branchOffice = await _ercContext.BranchOffices.FirstOrDefaultAsync(x => x.Id == request.Id);

            if (branchOffice is null)
            {
                throw new Exception("Branch Office not exist");
            }

            _ercContext.Entry(branchOffice).CurrentValues.SetValues(
                new
            {
                request.Name,
                request.Address,
                request.Iban,
                request.BankFullName,
                request.ChiefName,
                request.BookkeeperName
            });
            return(await _ercContext.SaveChangesAsync() > 0 ? Unit.Value : throw new Exception("Can't update branch office"));
        }
コード例 #8
0
        public async Task <int> SaveWorkAsync()
        {
            var domainEventEntities = _ercContext.ChangeTracker.Entries <IEntity>()
                                      .Select(po => po.Entity)
                                      .Where(po => po.Events.Any())
                                      .ToArray();

            var rows = await _ercContext.SaveChangesAsync();

            foreach (var entity in domainEventEntities)
            {
                var events = entity.Events.ToArray();
                entity.Events.Clear();
                foreach (var @event in events)
                {
                    @event.Id = entity.Id;
                    await _bus.Publish(@event, @event.GetType());
                }
            }

            return(rows);
        }