// TO DO: Use numeric constants below public async Task <Associate> Load(AssociateId id) { await using SqlCommand cmd = Db.Connection.CreateCommand(); cmd.CommandText = "SELECT ID, DUNSNumber, LongName, ShortName, IsParent, BusinessAssociateType, StatusId FROM Associate" + " WHERE ID = " + id.Value; Db.Connection.Open(); await using SqlDataReader reader = cmd.ExecuteReader(); if (!reader.Read()) { return(null); } Associate associate = new Associate(new AssociateId(Convert.ToInt32(reader[0]))) { DUNSNumber = DUNSNumber.Create(Convert.ToInt32(reader[1])), LongName = LongName.Create(reader[2].ToString()), ShortName = ShortName.Create(reader[3].ToString()), IsParent = Convert.ToBoolean(reader[4]), AssociateType = (AssociateType)reader[5], Status = (Status)reader[6] }; return(associate); }
#pragma warning disable 1998 public async Task <ActionResult <InternalAssociate> > Create([FromBody] CreateInternalAssociateDto item) #pragma warning restore 1998 { Result <DUNSNumber> dunsNumberOrError = DUNSNumber.Create(item.DUNSNumber); Result <LongName> longNameOrError = LongName.Create(item.LongName); Result <ShortName> shortNameOrError = ShortName.Create(item.ShortName); Result result = Result.Combine(dunsNumberOrError, longNameOrError, shortNameOrError); //if (result.IsFailure) // return Error(result.Error); InternalAssociate internalAssociate = new InternalAssociate(dunsNumberOrError.Value, longNameOrError.Value, shortNameOrError.Value, InternalAssociateType.LDC_FACILITY); _repository.AddInternalAssociate(internalAssociate); return(CreatedAtAction("Create", new { id = internalAssociate.Id }, internalAssociate)); }
public static Associate Create(int associateId, int dunsNumber, string longName, string shortName, bool isParent, bool isInternal, bool isDeactivating, AssociateTypeLookup associateType, StatusCodeLookup statusCode) { return(new Associate { Id = associateId, DUNSNumber = DUNSNumber.Create(dunsNumber), LongName = LongName.Create(longName), ShortName = ShortName.Create(shortName), IsParent = isParent, IsInternal = isInternal, IsDeactivating = isDeactivating, AssociateType = associateType, AssociateTypeId = associateType.AssociateTypeId, StatusCode = statusCode, StatusCodeId = statusCode.StatusCodeId }); }
//public void AddOperatingContext(AssociateId associateId, OperatingContextType operatingContextType, DatabaseId facilityId, // DatabaseId thirdPartySupplierId, AssociateType externalBATypeId, NullableDatabaseId certificationId, bool isDeactivating, // int legacyId, DatabaseId primaryAddressId, DatabaseId primaryEmailId, DatabaseId primaryPhoneId, DatabaseId providerTypeId, // DateTime startDate, Status status) //{ // OperatingContext operatingContext = new OperatingContext(operatingContextType, facilityId, thirdPartySupplierId, // externalBATypeId, certificationId, isDeactivating, legacyId, primaryAddressId, primaryEmailId, primaryPhoneId, // providerTypeId, startDate, status); // if (AssociateOperatingContexts == null) // { // AssociateOperatingContexts = new List<AssociateOperatingContext>(); // } // if (OperatingContexts == null) // { // OperatingContexts = new List<OperatingContext>(); // } // OperatingContexts.AddAssociate(operatingContext); // Apply(new Events.AssociateAddNewOperatingContext // { // AssociateId = associateId, // OperatingContextType = (int)operatingContextType, // FacilityId = facilityId, // ThirdPartySupplierId = thirdPartySupplierId, // ActingBATypeId = (int)externalBATypeId, // CertificationId = certificationId, // IsDeactivating = isDeactivating, // LegacyId = legacyId, // PrimaryAddressId = primaryAddressId, // PrimaryEmailId = primaryEmailId, // PrimaryPhoneId = primaryPhoneId, // ProviderTypeId = providerTypeId, // StartDate = startDate, // StatusCodeId = (int)status // }); //} protected override void When(object @event) { switch (@event) { case Events.AssociateCreated e: Id = new AssociateId(e.Id); break; case Events.AssociateDUNSNumberUpdated e: DUNSNumber = DUNSNumber.Create(e.DUNSNumber); break; case Events.AssociateIsParentUpdated e: IsParent = e.IsParent; break; case Events.AssociateLongNameUpdated e: LongName = LongName.Create(e.LongName); break; case Events.AssociateShortNameUpdated e: ShortName = ShortName.Create(e.ShortName); break; case Events.AssociateStatusUpdated e: StatusCode = StatusCodeLookup.StatusCodes[e.Status]; break; case Events.AssociateTypeUpdated e: AssociateType = AssociateTypeLookup.AssociateTypes[e.AssociateType]; break; case Events.AssociateAddNewOperatingContext e: OperatingContext operatingContext = new OperatingContext(Apply); ApplyToEntity(operatingContext, e); //OperatingContexts.AddAssociate(operatingContext); break; default: throw new Exception("Unknown event type " + @event); } }
#pragma warning disable 1998 public async Task <ActionResult <ExternalAssociate> > PutAssociate([FromBody] UpdateExternalAssociateDto item) #pragma warning restore 1998 { Result <DUNSNumber> dunsNumberOrError = DUNSNumber.Create(item.DUNSNumber); Result <LongName> longNameOrError = LongName.Create(item.LongName); Result <ShortName> shortNameOrError = ShortName.Create(item.ShortName); Result result = Result.Combine(dunsNumberOrError, longNameOrError, shortNameOrError); if (result.IsFailure) { return(Error(result.Error)); } ExternalAssociate externalAssociate = new ExternalAssociate(dunsNumberOrError.Value, longNameOrError.Value, shortNameOrError.Value, ExternalAssociateType.SELF_PROVIDER); _repository.UpdateExternalAssociate(externalAssociate); return(NoContent()); }
#pragma warning disable 1998 public async Task <ActionResult <InternalAssociate> > GetAssociate(int id) #pragma warning restore 1998 { //var egmsAssociate = await _context.BusinessAssociates.FindAsync(id); //if (egmsAssociate == null) //{ // return NotFound(); //} DUNSNumber aglDUNSNumber = DUNSNumber.Create(123456789).Value; LongName aglLongName = LongName.Create("AtlantaGasLight").Value; ShortName aglShortName = ShortName.Create("AGL").Value; InternalAssociate internalAssociate = new InternalAssociate(aglDUNSNumber, aglLongName, aglShortName, InternalAssociateType.LDC_FACILITY) { Status = Status.ACTIVE }; return(internalAssociate); }
private CustomerRM CreateCustomerForAssociate(Commands.V1.Customer.CreateForAssociate cmd) { Customer customer = Customer.Create(_customers++, cmd.StartDate, cmd.EndDate, cmd.StatusCodeId, cmd.NominationLevelId, AccountNumber.Create(cmd.AccountNumber), cmd.CustomerTypeId, cmd.DeliveryTypeId, DUNSNumber.Create(cmd.DUNSNumber), LongName.Create(cmd.LongName), ShortName.Create(cmd.ShortName), cmd.LDCId, cmd.LossTierTypeId, cmd.DeliveryLocationId, cmd.ShipperId, cmd.DeliveryPressure, cmd.MDQ, cmd.MaxHourlyInterruptible, cmd.MaxDailyInterruptible, cmd.HourlyInterruptible, cmd.DailyInterruptible, cmd.TotalHourlySpecifiedFirm, cmd.TotalDailySpecifiedFirm, cmd.InterstateSpecifiedFirm, cmd.IntrastateSpecifiedFirm, cmd.CurrentDemand, cmd.PreviousDemand, cmd.GroupTypeId, cmd.BalancingLevelId, new NAICSCode(cmd.NAICSCode), SICCode.Create(cmd.SICCode), cmd.SICCodePercentage, cmd.ShippersLetterFromDate, cmd.ShippersLetterToDate, cmd.SS1, cmd.IsFederal, cmd.TurnOffDate, cmd.TurnOnDate); if (_repository.CustomerExistsForAssociate(customer, cmd.AssociateId)) { throw new InvalidOperationException($"Customer already exists for Associate {cmd.AssociateId}"); } _repository.AddCustomerForAssociate(customer, cmd.AssociateId); return(Conversions.GetCustomerRM(customer)); }
static void Main() { //internalAssociateController.PutAssociate(); InternalAssociate atlantaGasLight = AddInternalAssociate(123456789, "AtlantaGasLight", "AGL"); ExternalAssociate transco = AddExternalAssociate(123456790, "Transco", "TRX"); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Add an Operating Context to an internal business associate for a particular LDC atlantaGasLight.AddOperatingContext(); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Add an External BA Operating Context to an external business associate for a // particular LDC, set the Provider Type to Marketer and generate a new Third-Party Supplier Id for the new operating context. transco.AddOperatingContext(new ExternalOperatingContext(ProviderType.MARKETER)); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Add an External BA Operating Context to an external business associate for a // particular LDC, set the Provider Type to Pooler and generate a new Third-Party Supplier Id for the new operating context. transco.AddOperatingContext(new ExternalOperatingContext(ProviderType.POOLER)); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Add an External BA Operating Context to an external business associate for a // particular LDC, set the Provider Type to Shipper and generate a new Third-Party Supplier Id for the new operating context. transco.AddOperatingContext(new ExternalOperatingContext(ProviderType.SHIPPER)); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Add an External BA Operating Context to an external business associate for a // particular LDC, set the Provider Type to Supplier and generate a new Third-Party Supplier Id for the new operating context. transco.AddOperatingContext(new ExternalOperatingContext(ProviderType.SUPPLIER)); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Add an External BA Operating Context to an external business associate for a // particular LDC, set the Provider Type to Asset Manager and generate a new Third-Party Supplier Id for the new operating context. transco.AddOperatingContext(new ExternalOperatingContext(ProviderType.ASSET_MANAGER)); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Update the status of an External BA Operating Context for an external business associate from Pending to Active transco.OperatingContexts[0].Status = Status.ACTIVE; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Add a new Agent Relationship for two external business associates // TO DO: Add Start Date, End Date DUNSNumber transcoAgentsDUNSNumber = DUNSNumber.Create(123456791).Value; LongName longName = LongName.Create("TranscoAgents").Value; ShortName shortName = ShortName.Create("TRXA").Value; Agent transcoAgents = new Agent(transcoAgentsDUNSNumber, longName, shortName, ExternalAssociateType.SELF_PROVIDER) { OperatingContexts = new List <OperatingContext> { new ExternalOperatingContext() } }; AgentRelationship agentRelationship = new AgentRelationship(transco, transcoAgents); transco.AddAgentRelationship(agentRelationship); Role roleA = new Role(); UserOperatingContext userOperatingContextA = new UserOperatingContext { Role = roleA }; agentRelationship.AgentUserList.Add(userOperatingContextA); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Terminate an existing Agent Relationship for two external business associates // The specs call for setting the end date, but we have instead added an active flag. agentRelationship.IsActive = false; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Modify an existing Agent Relationship for two external business associates by adding a // new user to the relationship, modifying the role of a user within a relationship or // remove a user from the relationship. UserOperatingContext userOperatingContextB = new UserOperatingContext(); agentRelationship.AgentUserList.Add(userOperatingContextB); Role roleB = new Role(); userOperatingContextB.Role = roleB; agentRelationship.AgentUserList.Remove(userOperatingContextB); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Add a new Asset Manager Relationship for an external business associate and an internal business associate AssetManagerRelationship assetManagerRelationship = new AssetManagerRelationship(atlantaGasLight, transcoAgents); transco.AgentRelationships.Add(agentRelationship); assetManagerRelationship.AssetManagerUserList.Add(userOperatingContextA); atlantaGasLight.AssetManagerRelationships.Add(assetManagerRelationship); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Modify an existing Asset Manager Relationship by adding a new user // to the relationship, modifying the role of a user within a relationship // or remove a user from the relationship. assetManagerRelationship.AssetManagerUserList.Add(userOperatingContextB); userOperatingContextB.Role = roleB; assetManagerRelationship.AssetManagerUserList.Remove(userOperatingContextA); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // JOEF: Assuming that this is not a legitimate use case until we get clarification // Designate an external business associate as a shipper for a particular market }
#pragma warning disable 1998 public async Task <object> Handle(object command) #pragma warning restore 1998 { switch (command) { #region Associates case Commands.V1.Associate.Create cmd: return(CreateAssociate(cmd)); case Commands.V1.Associate.UpdateDUNSNumber cmd: UpdateAssociate(cmd.Id, ia => ia.UpdateDUNSNumber(DUNSNumber.Create(cmd.DUNSNumber))); break; case Commands.V1.Associate.UpdateAssociateType cmd: UpdateAssociate(cmd.Id, ia => ia.UpdateAssociateType(AssociateTypeLookup.AssociateTypes[cmd.AssociateType])); break; case Commands.V1.Associate.UpdateLongName cmd: UpdateAssociate(cmd.Id, ia => ia.UpdateLongName(LongName.Create(cmd.LongName))); break; case Commands.V1.Associate.UpdateIsParent cmd: UpdateAssociate(cmd.Id, ia => ia.UpdateIsParent(cmd.IsParent)); break; case Commands.V1.Associate.UpdateStatus cmd: UpdateAssociate(cmd.Id, ia => ia.UpdateStatus(StatusCodeLookup.StatusCodes[cmd.Status])); break; case Commands.V1.Associate.UpdateShortName cmd: UpdateAssociate(cmd.Id, ia => ia.UpdateShortName(ShortName.Create(cmd.ShortName))); break; case Commands.V1.Associate.Phone.CreateForAssociate cmd: return(CreatePhoneForAssociate(cmd)); case Commands.V1.Associate.EMail.CreateForAssociate cmd: return(CreateEMailForAssociate(cmd)); #endregion #region AgentRelationship case Commands.V1.AgentRelationship.CreateForPrincipal cmd: return(CreateAgentRelationshipForPrincipal(cmd)); case Commands.V1.AgentRelationship.User.CreateForAgent cmd: return(CreateUserForAgent(cmd)); #endregion #region Contact case Commands.V1.Contact.CreateForAssociate cmd: return(CreateContactForAssociate(cmd)); case Commands.V1.Contact.Address.CreateForContact cmd: return(CreateAddressForContact(cmd)); case Commands.V1.Contact.Address.Update cmd: UpdateAddressForContact(cmd); break; case Commands.V1.Contact.ContactConfiguration.CreateForContact cmd: return(CreateContactConfigurationForContact(cmd)); case Commands.V1.Contact.EMail.CreateForContact cmd: return(CreateEMailForContact(cmd)); case Commands.V1.Contact.Phone.CreateForContact cmd: return(CreatePhoneForContact(cmd)); #endregion #region Customer case Commands.V1.Customer.CreateForAssociate cmd: return(CreateCustomerForAssociate(cmd)); case Commands.V1.Customer.AlternateFuel.CreateForCustomer cmd: return(CreateAlternateFuelForCustomer(cmd)); #endregion case Commands.V1.EGMSPermission.Create cmd: return(CreateEGMSPermission(cmd)); case Commands.V1.Role.Create cmd: return(CreateRole(cmd)); case Commands.V1.RoleEGMSPermission.Create cmd: return(CreateRoleEGMSPermission(cmd)); case Commands.V1.User.CreateForAssociate cmd: return(CreateUserForAssociate(cmd)); #region OperatingContext case Commands.V1.OperatingContext.CreateForAssociate cmd: return(CreateOperatingContextForAssociate(cmd)); case Commands.V1.OperatingContext.CreateForCustomer cmd: return(CreateOperatingContextForCustomer(cmd)); case Commands.V1.Associate.Address.CreateForAssociate cmd: return(CreateAddressForAssociate(cmd)); case Commands.V1.OperatingContext.Certification.CreateForOperatingContext cmd: return(CreateCertificationForOperatingContext(cmd)); case Commands.V1.OperatingContext.Customer.CreateForOperatingContext cmd: return(CreateCustomerForOperatingContext(cmd)); case Commands.V1.OperatingContext.Customer.AlternateFuel.CreateForCustomer cmd: return(CreateAlternateFuelForCustomer(cmd)); case Commands.V1.OperatingContext.Update cmd: UpdateOperatingContext(cmd); return(null); #endregion default: throw new InvalidOperationException($"Commands type {command.GetType().FullName} is unknown"); } return(null); }