public async Task Handle(AddNewContractorCommand command, IMessageHandlerContext messageContext)
        {
            try
            {
                var contractorDto       = command.Contractor;
                ContractorStatus status = ContractorStatus.Open;
                var contractDuration    = new DateTimeRange(contractorDto.ContractStartDate, contractorDto.ContractEndDate);
                var contact             = new Contact(new Name(contractorDto.ContactFirstName, contractorDto.ContactLastName), contractorDto.ContactPhoneNumber, contractorDto.ContactAlternatePhoneNumber, contractorDto.ContactEmail);

                var            contractrorAddress = new VO.Address(contractorDto.AddressLine1, contractorDto.AddressLine2, contractorDto.City, contractorDto.StateCode, contractorDto.ZipCode);
                ContractorType type             = contractorDto.Type;
                var            contractorSuffix = _contractorSuffixGenerator.GetContractorSuffixForNewContractor(contractorDto.EinNumber, type);
                //TODO: User should be sending the GUIDs, leaving it for testing to do auto generated guid
                var contractor = new Entities.Contractor(contractorDto.EinNumber + contractorSuffix, contractorDto.ContractorName, contractorDto.DoingBusinessAs, status, type, contractDuration,
                                                         contractorDto.PhoneNumber, contact, contractrorAddress, contractorDto.Email);
                _contractorRepository.AddContractor(contractor);
                await _contractorRepository.SaveAsync();

                await Task.WhenAll(messageContext.Publish(new CommandCompletedEvent(command.Id, DateTime.UtcNow)),
                                   messageContext.Publish(new ContractorAdded(DateTime.Now, contractor.Id, contractor.EinNumber)
                {
                    ContractorEin = contractor.EinNumber
                }));
            }
            catch (Exception ex)
            {
                //TODO: Global Exception logging
                await messageContext.Publish(new CommandFailedEvent(command.Id, ex, DateTime.UtcNow));

                throw;
            }
        }
Esempio n. 2
0
        private void SetContractorSuspensionNotice()
        {
            if (ContractorStatus.ToUpper() != "A" || ContractorId.ToUpper() == "OWNER" || PermitTypeString == "FR")
            {
                return;
            }



            if (ContractorLiabilityInsuranceExpDate < DateTime.Today.Date.AddDays(9))
            {
                ContractorWarning = "The Contractor's Liability Insurance will expire on " +
                                    ContractorLiabilityInsuranceExpDate.ToShortDateString();
                return;
            }
            if (WorkersCompExpirationDate != DateTime.MinValue &&
                WorkersCompExpirationDate < DateTime.Today.Date.AddDays(9))
            {
                ContractorWarning = "The Contractor's Workman's Compensation Insurance will expire on " +
                                    WorkersCompExpirationDate.ToShortDateString();
                return;
            }

            if ((Inspection_Notice == "180+" &&
                 ContractorSuspendGraceDate < DateTime.Today.Date.AddDays(9)) ||
                (ContractorWarning.Length == 0 && Inspection_Notice == "151-180")
                )
            {
                ContractorWarning = @"In danger of privilege suspension based on permit age.";
                return;
            }

            if (ContractorStateCertExpDate < DateTime.Today.AddDays(9) ||
                ContractorCountyLicenseExpDate < DateTime.Today.Date.AddDays(9))
            {
                if (ContractorStateCertExpDate < DateTime.Today.Date.AddDays(9) &&
                    ContractorStateCertExpDate != DateTime.MinValue)
                {
                    ContractorWarning = @"Contractor's State Certification will expire on: " +
                                        ContractorStateCertExpDate.ToShortDateString();
                    return;
                }

                if (ContractorCountyLicenseExpDate < DateTime.Today.Date.AddDays(9) &&
                    ContractorCountyLicenseExpDate != DateTime.MinValue &&
                    ContractorStateCertExpDate < DateTime.Today.Date.AddDays(9) &&
                    ContractorStateCertExpDate != DateTime.MinValue)
                {
                    ContractorWarning = "Contractor's County License will expire on: " +
                                        ContractorCountyLicenseExpDate.ToShortDateString();
                    return;
                }
            }
        }
Esempio n. 3
0
 public Contractor(Guid id, string einNumber, string contractorName, string doingBusinessAs, ContractorStatus status, ContractorType type, DateTimeRange contractDuration,
                   PhoneNumber primaryPhoneNumber, Contact contactDetails, VO.Address address, string email) : base(id)
 {
     //TODO: Implement guard conditions
     Id               = id;
     EinNumber        = einNumber;
     ContractorName   = contractorName;
     DoingBusinessAs  = doingBusinessAs;
     Status           = status;
     ContractorType   = type;
     ContractDuration = contractDuration;
     PhoneNumber      = primaryPhoneNumber;
     Contact          = contactDetails;
     Address          = address;
     Email            = email;
     InitializeState();
 }
Esempio n. 4
0
 public Contractor(Guid id, string einNumber, string contractorName, string doingBusinessAs, ContractorStatus status, ContractorType type, DateTimeRange contractDuration,
     PhoneNumber primaryPhoneNumber, Contact contactDetails,VO.Address address, string email)
     : base(id)
 {
     //TODO: Implement guard conditions
     Id = id;
     EinNumber = einNumber;
     ContractorName = contractorName;
     DoingBusinessAs = doingBusinessAs;
     Status = status;
     ContractorType = type;
     ContractDuration = contractDuration;
     PhoneNumber = primaryPhoneNumber;
     Contact = contactDetails;
     Address = address;
     Email = email;
     InitializeState();
 }
Esempio n. 5
0
 public DocumentView(Document document, Source source, Contractor contractor)
 {
     DocumentId            = document.DocumentId;
     DocumentDate          = document.DocumentDate;
     SourceDescription     = source.Code;
     SaleDate              = document.SaleDate;
     DocumentNumber        = document.DocumentNumber;
     DocumentStatus        = document.DocumentStatus;
     DocumentSymbol        = document.DocumentSymbol;
     JpkV7                 = document.JpkV7;
     ContractorId          = contractor.ContractorId;
     ContractorName        = contractor.Name;
     ContractorVatId       = contractor.VatId;
     ContractorCountryCode = contractor.CountryCode;
     ContractorStatus      = contractor.ContractorStatus;
     Net   = document.Net;
     Vat   = document.Vat;
     Gross = document.Gross;
 }
Esempio n. 6
0
 public Contractor(string einNumber, string contractorName, string doingBusinessAs, ContractorStatus status, ContractorType type, DateTimeRange contractDuration,
                   PhoneNumber primaryPhoneNumber, Contact contactDetails, VO.Address address, string email)
     : this(GuidHelper.NewSequentialGuid(), einNumber, contractorName, doingBusinessAs, status, type, contractDuration, primaryPhoneNumber, contactDetails, address, email)
 {
 }
Esempio n. 7
0
 public Contractor(string einNumber, string contractorName, string doingBusinessAs, ContractorStatus status, ContractorType type, DateTimeRange contractDuration, 
     PhoneNumber primaryPhoneNumber, Contact contactDetails, VO.Address address, string email)
     : this(GuidHelper.NewSequentialGuid(), einNumber, contractorName, doingBusinessAs, status, type, contractDuration, primaryPhoneNumber, contactDetails, address, email)
 {
 }
Esempio n. 8
0
        public async Task <IActionResult> ChangeContractorStatus([FromBody] int contractorId, [FromBody] ContractorStatus contractorStatus)
        {
            var contractor = await _context.Contractors.FirstOrDefaultAsync(c => c.ContractorId == contractorId);

            if (contractor != null)
            {
                contractor.ContractorId = contractorId;
                try
                {
                    _context.Update(contractor);
                    await _context.SaveChangesAsync();
                }
                catch
                {
                    return(new StatusCodeResult((int)HttpStatusCode.BadRequest));
                }
                return(new StatusCodeResult((int)HttpStatusCode.OK));
            }
            return(new StatusCodeResult((int)HttpStatusCode.NotFound));
        }