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;
            }
        }
Beispiel #2
0
        internal Site(SiteState siteState /*, IBus bus*/) : base(siteState.Id /*, bus*/)
        {
            SiteName           = siteState.SiteName;
            SiteNumber         = siteState.SiteNumber;
            Id                 = siteState.Id;
            Address            = new VO.Address(siteState.AddressLine1, siteState.AddressLine2, siteState.City, siteState.StateCode, siteState.ZipCode);
            ContactDetails     = new Contact(new Name(siteState.ContactFirstName, siteState.ContactLastName), siteState.ContactPhoneNumber, siteState.ContactAlternatePhoneNumber, siteState.ContactEmail);
            ContractDuration   = new DateTimeRange(siteState.ContractStartDate, siteState.ContractEndDate);
            CountyCode         = siteState.CountyCode;
            CountyServedCode   = siteState.CountyServedCode;
            Email              = siteState.Email;
            LicencingStatus    = siteState.LicencingStatusCode;
            PrimaryPhoneNumber = siteState.PhoneNumber;
            SiteFacitlityType  = siteState.SiteFacilityTypeCode;
            SiteType           = siteState.SiteTypeCode;
            Status             = siteState.StatusCode;
            _holidays          = siteState.SiteHoliday.Select(x => new SiteHoliday(x.HolidayDate, x.HolidayName)).ToList();
            _rates             =
                siteState.SiteRate.Select(
                    x =>
                    new SiteRate(x.AgeCode, x.RegularCareDailyRate.GetValueOrDefault(),
                                 x.RegularCareWeeklyRate.GetValueOrDefault(), x.EffectiveDate /*, bus*/)).ToList();

            DbState = siteState;
        }
Beispiel #3
0
        internal Site(SiteState siteState/*, IBus bus*/)
            : base(siteState.Id/*, bus*/)
        {
            SiteName = siteState.SiteName;
            SiteNumber = siteState.SiteNumber;
            Id = siteState.Id;
            Address = new VO.Address(siteState.AddressLine1, siteState.AddressLine2, siteState.City, siteState.StateCode, siteState.ZipCode);
            ContactDetails = new Contact(new Name(siteState.ContactFirstName, siteState.ContactLastName), siteState.ContactPhoneNumber, siteState.ContactAlternatePhoneNumber, siteState.ContactEmail);
            ContractDuration = new DateTimeRange(siteState.ContractStartDate, siteState.ContractEndDate);
            CountyCode = siteState.CountyCode;
            CountyServedCode = siteState.CountyServedCode;
            Email = siteState.Email;
            LicencingStatus = siteState.LicencingStatusCode;
            PrimaryPhoneNumber = siteState.PhoneNumber;
            SiteFacitlityType = siteState.SiteFacilityTypeCode;
            SiteType = siteState.SiteTypeCode;
            Status = siteState.StatusCode;
            _holidays = siteState.SiteHoliday.Select(x => new SiteHoliday(x.HolidayDate, x.HolidayName)).ToList();
            _rates =
                siteState.SiteRate.Select(
                    x =>
                        new SiteRate(x.AgeCode, x.RegularCareDailyRate.GetValueOrDefault(),
                            x.RegularCareWeeklyRate.GetValueOrDefault(), x.EffectiveDate/*, bus*/)).ToList();

            DbState = siteState;
        }
Beispiel #4
0
        internal Contractor(ContractorState contDbState /*, IBus bus*/) : base(contDbState.Id /*, bus*/)
        {
            DbState = contDbState;

            Contact          = new Contact(new Name(contDbState.ContactFirstName, contDbState.ContactLastName), contDbState.ContactPhoneNumber, contDbState.ContactAlternatePhoneNumber, contDbState.ContactEmail);
            Address          = new VO.Address(contDbState.AddressLine1, contDbState.AddressLine2, contDbState.City, contDbState.StateCode, contDbState.ZipCode);
            EinNumber        = contDbState.EinNumber;
            ContractorName   = contDbState.ContractorName;
            DoingBusinessAs  = contDbState.DoingBusinessAs; ContractorType = contDbState.Type;
            ContractDuration = new DateTimeRange(contDbState.ContractStartDate, contDbState.ContractEndDate);
            PhoneNumber      = contDbState.PhoneNumber;
            Email            = contDbState.Email;
            ContractorAlternatePhoneNumber = contDbState.AlternatePhoneNumber;
            Status = contDbState.Status;
            ContractorSuffixCode = contDbState.EinNumber.Substring(9, 2);
        }
Beispiel #5
0
        public void UpdateAddress(string addressLine1, string addressLine2, string city, string stateCode, string zipCode)
        {
            var newAddress = new VO.Address(addressLine1, addressLine2, city, stateCode, zipCode);

            if (Address != newAddress)
            {
                //TODO: NSB Update
                //Bus.Publish(new ContractorAddressChanged(EinNumber,Address,newAddress));
                Address = newAddress;
                DbState.AddressLine1 = addressLine1;
                DbState.AddressLine2 = addressLine2;
                DbState.City         = city;
                DbState.StateCode    = stateCode;
                DbState.ZipCode      = zipCode;
            }
        }
Beispiel #6
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();
 }
        internal Contractor(ContractorState contDbState/*, IBus bus*/)
            : base(contDbState.Id/*, bus*/)
        {
            DbState = contDbState;

            Contact = new Contact(new Name(contDbState.ContactFirstName, contDbState.ContactLastName), contDbState.ContactPhoneNumber, contDbState.ContactAlternatePhoneNumber, contDbState.ContactEmail);
            Address = new VO.Address(contDbState.AddressLine1, contDbState.AddressLine2, contDbState.City, contDbState.StateCode, contDbState.ZipCode);
            EinNumber = contDbState.EinNumber;
            ContractorName = contDbState.ContractorName;
            DoingBusinessAs =  contDbState.DoingBusinessAs; ContractorType =  contDbState.Type;
            ContractDuration = new DateTimeRange(contDbState.ContractStartDate, contDbState.ContractEndDate);
            PhoneNumber =   contDbState.PhoneNumber;
            Email = contDbState.Email;
            ContractorAlternatePhoneNumber = contDbState.AlternatePhoneNumber;
            Status = contDbState.Status;
            ContractorSuffixCode = contDbState.EinNumber.Substring(9, 2);
        }
Beispiel #8
0
 //TODO: See how we can avoid injecting EventBus into the Domain entities
 public Site(Guid id, int siteNumber, string siteName, SiteStatus status, SiteFacilityType siteFacitlityType, SiteType siteType,
             DateTimeRange contractDuration, PhoneNumber primaryPhoneNumber, Contact contactDetails, VO.Address address, string email,
             string countyCode, string countyServedCode, LicenceStatus licenceStatus, IEnumerable <SiteHoliday> holidays, IEnumerable <SiteRate> rates /*, IBus bus*/) : base(id /*, bus*/)
 {
     SiteNumber         = siteNumber;
     SiteName           = siteName;
     Status             = status;
     SiteFacitlityType  = siteFacitlityType;
     SiteType           = siteType;
     ContractDuration   = contractDuration;
     PrimaryPhoneNumber = primaryPhoneNumber;
     ContactDetails     = contactDetails;
     Address            = address;
     Email            = email;
     CountyCode       = countyCode;
     CountyServedCode = countyServedCode;
     LicencingStatus  = licenceStatus;
     InitializeDbState();
     holidays.ForEach(AddNewHoliday);
     rates.ForEach(AddNewSiteRate);
 }
Beispiel #9
0
        public async Task Handle(AddNewSiteCommand message, IMessageHandlerContext messageContext)
        {
            var siteDto = message.Site;
            SiteFacilityType facitlType = siteDto.SiteFacitlityTypeCode;
            SiteType         siteType   = siteDto.SiteTypeCode;
            var contractDuration        = new DateTimeRange(siteDto.ContractStartDate, siteDto.ContractEndDate);
            var contact = new Contact(new Name(siteDto.ContactFirstName, siteDto.ContactLastName),
                                      siteDto.ContactPhoneNumber, null, siteDto.ContactEmailText);
            var address = new DDD.Domain.Common.ValueObjects.Address(siteDto.AddressLine1, siteDto.AddressLine2,
                                                                     siteDto.City, "DE", siteDto.ZipCode, siteDto.CountyCode);

            var holidays   = siteDto.SiteHolidays.Select(x => new SiteHoliday(x.HolidayDate, x.HolidayName)).ToList();
            var rates      = siteDto.SiteRates.Select(x => new SiteRate(x.MinAge, x.Rate, (x.Rate * 1.5m), DateTime.Now));
            var siteEntity = new Entities.Site(GuidHelper.NewSequentialGuid(), siteDto.SiteNumber, siteDto.SiteName,
                                               SiteStatus.Active, facitlType, siteType,
                                               contractDuration, siteDto.PhoneNumber, contact, address, siteDto.SiteEmailText, siteDto.CountyCode,
                                               siteDto.CountyServed
                                               , LicenceStatus.Licenced, holidays, rates);

            _siteRepository.Add(siteEntity);
            await _siteRepository.SaveAsync();

            await messageContext.Publish(new NewSiteAdded(siteEntity.Id, siteEntity.SiteNumber));
        }
Beispiel #10
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)
 {
 }
Beispiel #11
0
 public void UpdateAddress(string addressLine1, string addressLine2, string city,string stateCode,string zipCode)
 {
     var newAddress = new VO.Address(addressLine1,addressLine2,city,stateCode,zipCode);
     if (Address != newAddress)
     {
         //TODO: NSB Update
         //Bus.Publish(new ContractorAddressChanged(EinNumber,Address,newAddress));
         Address = newAddress;
         DbState.AddressLine1 = addressLine1;
         DbState.AddressLine2 = addressLine2;
         DbState.City = city;
         DbState.StateCode = stateCode;
         DbState.ZipCode = zipCode;
     }
 }
Beispiel #12
0
 public Site(int siteId, string siteName, SiteStatus status, SiteFacilityType siteFacitlityType, SiteType siteType,
             DateTimeRange contractDuration, PhoneNumber primaryPhoneNumber, Contact contactDetails, VO.Address address, string email,
             string county, string countyServed, LicenceStatus licenceStatus, IEnumerable <SiteHoliday> holidays, IEnumerable <SiteRate> rates /*, IBus eventBus*/)
     : this(GuidHelper.NewSequentialGuid(), siteId, siteName, status, siteFacitlityType, siteType, contractDuration, primaryPhoneNumber, contactDetails, address, email, county, countyServed, licenceStatus, holidays, rates /*, eventBus*/)
 {
 }