public async Task <Unit> Handle(CreateContactCommand request, CancellationToken cancellationToken) { var entity = new Contact { //ContactNumber = request.ContactNumber, ContactNumber = "C-000", IdentificationNumber = request.IdentificationNumber, Name = request.Name, LastName = request.LastName, Email = request.Email, Gender = request.Gender, PhoneNumberOne = request.PhoneNumberOne, PhoneNumberTwo = request.PhoneNumberTwo, ZoneId = request.ZoneId }; entity.Address = new Address { AddressDataId = request.AddressDataId, Refference = request.Address, Street = request.Street, AddressTypeId = request.AddressTypeId }; _context.Contacts.Add(entity); await _context.SaveChangesAsync(cancellationToken); entity.ContactNumber = SetCode(entity.Id); _context.Update(entity); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(CreateLoanCommand request, CancellationToken cancellationToken) { var entity = new Loan { ContactId = request.ContactId, UrlFile = request.UrlFile, TimeFrameId = request.TimeFrameId, LoanAmount = request.LoanAmount, SimpleInterest = request.SimpleInterest, InterestRate = request.InterestRate, Interest = request.Interest, LoanDate = request.LoanDate, EndDate = request.EndDate, NumberOfDue = request.NumberOfDue, TotalBalance = request.TotalBalance, IsActive = request.IsActive, UpToDate = request.UpToDate, Code = "L-000", TotalCapitalAmount = request.TotalCapitalAmount }; _context.Loans.Add(entity); await _context.SaveChangesAsync(cancellationToken); entity.Code = SetCode(entity.Id); _context.Update(entity); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(CreateLoanWithDuesCommand request, CancellationToken cancellationToken) { var entity = new Loan { ContactId = request.ContactId, UrlFile = request.UrlFile, TimeFrameId = request.TimeFrameId, LoanAmount = request.LoanAmount, SimpleInterest = request.SimpleInterest, InterestRate = request.InterestRate, Interest = request.Interest, LoanDate = request.LoanDate, EndDate = request.EndDate, NumberOfDue = request.NumberOfDue, TotalBalance = request.TotalBalance, IsActive = request.IsActive, UpToDate = request.UpToDate, Code = "L-000", TotalCapitalAmount = request.TotalCapitalAmount }; decimal capitalAmount = request.LoanAmount / request.NumberOfDue; decimal interest = request.Interest / request.NumberOfDue; var timeFrame = await _context.TimeFrames.SingleAsync(tf => tf.Id == request.TimeFrameId); for (int i = 1; i <= request.NumberOfDue; i++) { DateTime date = request.LoanDate.AddDays(timeFrame.CountDay * i); entity.Dues.Add(new Due { CapitalAmount = capitalAmount, InterestAmount = interest, PaymentAmount = capitalAmount + interest, LateFee = 0, PendingBalance = 0, DueNumber = i, Date = date, DueIsPaidOff = false }); } _context.Loans.Add(entity); await _context.SaveChangesAsync(cancellationToken); entity.Code = SetCode(entity.Id); _context.Update(entity); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(UpdateCollectorCommand request, CancellationToken cancellationToken) { var entity = await _context.Collectors.Include(z => z.ZoneCollectors).SingleAsync(c => c.Id == request.Id, cancellationToken); if (entity == null) { throw new NotFoundException(nameof(Collectors), request.Id); } entity.Name = request.Name; entity.Address = request.Address; entity.PhoneNumberOne = request.PhoneNumberOne; entity.PhoneNumberTwo = request.PhoneNumberTwo; entity.Email = request.Email; entity.UpdateZones(request.Zones.ToArray()); _context.Update(entity); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }