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"));
        }
예제 #2
0
        public async Task <Unit> Handle(OpenNewContractCommand request, CancellationToken cancellationToken)
        {
            var ap = await _ercContext.AccountingPoints.FindAsync(request.AccountingPointId);

            if (ap is null)
            {
                throw new Exception("Accounting point not exist");
            }

            var person = await _ercContext.People.FindAsync(request.PersonId);

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

            person.IdCardNumber       = request.IdCardNumber;
            person.IdCardIssuanceDate = request.IdCardIssuanceDate;
            person.IdCardIssuer       = request.IdCardIssuer;
            person.IdCardExpDate      = request.IdCardExpDate;
            person.TaxCode            = request.TaxCode;
            person.FirstName          = request.FirstName;
            person.LastName           = request.LastName;
            person.Patronymic         = request.Patronymic;
            person.MobilePhones       = request.MobilePhones;
            person.Email = request.Email;

            _ercContext.Entry(ap.Owner).State = person.Id == 0 ? EntityState.Added : EntityState.Modified;
            ap.OpenNewContract(request.ContractStartDate, person, request.CurrentUser, request.SendPaperBill);

            return(Unit.Value);
        }
예제 #3
0
        public void StartNewPeriod(int branchOfficeId)
        {
            lock (_sync)
            {
                var branchOffice = _dbContext.BranchOffices
                                   .Include(b => b.CurrentPeriod)
                                   .First(b => b.Id == branchOfficeId);

                var period = _dbContext.Periods.FirstOrDefault(p => p.StartDate == branchOffice.CurrentPeriod.EndDate.AddDays(1));

                using var transaction = _dbContext.Database.BeginTransaction();

                if (period is null)
                {
                    var start = branchOffice.CurrentPeriod.EndDate.AddDays(1);
                    var end   = start.AddMonths(1).AddDays(-1);
                    period = new Period(start, end);
                    _dbContext.Entry(period).State = EntityState.Added;
                }
                _mediator.Send(new CreateTaxInvoiceCommand(branchOfficeId: branchOfficeId, branchOffice.CurrentPeriod.Id));
                branchOffice.StartNewPeriod(period);
                // The current period before switching to a new one

                _dbContext.SaveChanges();
                _dbContext.Database.ExecuteSqlInterpolated($"insert into accounting_point_debt_history(accounting_point_id, period_id, debt_value) select id, {period.Id}, debt from accounting_points where branch_office_Id={branchOfficeId}");

                transaction.Commit();
            }
        }
        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"));
        }
        public async Task <IActionResult> Update(PaymentsBatch paymentsBatch)
        {
            var pc = await _ercContext.PaymentBatches.FindAsync(paymentsBatch.Id);

            if (pc is null)
            {
                return(NotFound());
            }

            _ercContext.Entry(pc).CurrentValues.SetValues(paymentsBatch);
            await _ercContext.SaveChangesAsync();

            return(Ok());
        }
예제 #6
0
        public async Task <Unit> Handle(UpdatePaymentCommand request, CancellationToken cancellationToken)
        {
            var payment = await _ercContext.Payments.Include(t => t.AccountingPoint).FirstOrDefaultAsync(x => x.Id == request.Id);

            if (payment is null)
            {
                throw new Exception("Payment not exist");
            }
            else if (payment.Status == PaymentStatus.Processed)
            {
                throw new Exception("The payment has been made and cannot be edited");
            }

            _ercContext.Entry(payment).CurrentValues.SetValues(request);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(UpdateAccountingPointCommand request, CancellationToken cancellationToken)
        {
            var ap = await _ercContext.AccountingPoints.FirstOrDefaultAsync(x => x.Id == request.Id);

            if (ap is null)
            {
                throw new Exception("Accounting point not exist");
            }

            var address = new Address
            {
                Id =
                    (await _ercContext.Addresses
                     .Where(a => a.StreetId == request.StreetId && a.Building == request.Building && ((a.Apt ?? string.Empty) == (request.Apt ?? string.Empty)))
                     .Select(a => (int?)a.Id)
                     .FirstOrDefaultAsync()) ?? 0,
                StreetId = request.StreetId,
                Building = request.Building,
                Apt      = request.Apt,
                Zip      = request.Zip
            };

            ap.SetNewAddress(address);
            _ercContext.Entry(ap).CurrentValues.SetValues(request);

            ap.Events.Add(new AccountingPointUpdated
            {
                StreetAddress        = ap.Address.StreetLocation,
                CityName             = ap.Address.CityName,
                Eic                  = ap.Eic,
                Name                 = ap.Name,
                PersonFirstName      = ap.Owner.FirstName,
                PersonIdCardNumber   = ap.Owner.IdCardNumber,
                PersonLastName       = ap.Owner.LastName,
                PersonPatronymic     = ap.Owner.Patronymic,
                PersonTaxCode        = ap.Owner.TaxCode,
                BranchOfficeStringId = ap.BranchOffice.StringId,
                BranchOfficeName     = ap.BranchOffice.Name
            });

            return(Unit.Value);
        }
예제 #8
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"));
        }