예제 #1
0
        // 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);
        }
예제 #2
0
        public bool Exists(AssociateId id)
        {
            using SqlCommand cmd = Db.Connection.CreateCommand();
            cmd.CommandText      = "SELECT DUNSNumber FROM Associate WHERE DUNSNumber = " + id.Value;

            Db.Connection.Open();

            using SqlDataReader reader = cmd.ExecuteReader();

            return(reader.HasRows);
        }
        private OperatingContextRM CreateOperatingContextForAssociate(Commands.V1.OperatingContext.CreateForAssociate cmd)
        {
            Associate associate = _repository.GetAssociate(AssociateId.FromInt(cmd.AssociateId));

            if (associate == null)
            {
                throw new InvalidOperationException($"Associate with id {cmd.AssociateId} cannot be found");
            }

            OperatingContext operatingContext = new OperatingContext(_operatingContexts++, OperatingContextTypeLookup.OperatingContextTypes[cmd.OperatingContextType], cmd.FacilityId,
                                                                     cmd.ThirdPartySupplierId, ExternalAssociateTypeLookup.ActingAssociateTypes[cmd.ActingBATypeID], cmd.CertificationId, cmd.IsDeactivating,
                                                                     cmd.LegacyId, cmd.PrimaryAddressId, cmd.PrimaryEmailId, cmd.PrimaryPhoneId,
                                                                     cmd.ProviderType, cmd.StartDate, StatusCodeLookup.StatusCodes[cmd.Status]);

            _repository.AddOperatingContextForAssociate(operatingContext, associate.Id);

            return(Conversions.GetOperatingContextRM(operatingContext));
        }
예제 #4
0
        //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);
            }
        }
예제 #5
0
        public void AddOperatingContext(AssociateId id, OperatingContext entity)
        {
            using SqlCommand cmd = Db.Connection.CreateCommand();

            Db.Connection.Open();
            cmd.Transaction = Db.Connection.BeginTransaction("AddOperatingContext");

            try
            {
                cmd.CommandText = "insert into OperatingContext(ActingBATypeId, CertificationId, FacilityId, IsDeactivating, LegacyId, OperatingContextTypeId, ProviderTypeId) VALUES( " +
                                  "@ActingBATypeId, @CertificationId, @FacilityId, @IsDeactivating, @LegacyId, @OperatingContextTypeId, @ProviderTypeId)";

                cmd.Parameters.AddWithValue("@ActingBATypeId", (int)entity.ActingBAType);
                cmd.Parameters.AddWithValue("@CertificationId", entity.CertificationId.Value);
                cmd.Parameters.AddWithValue("@FacilityId", entity.FacilityId.Value);
                cmd.Parameters.AddWithValue("@IsDeactivating", entity.IsDeactivating);
                cmd.Parameters.AddWithValue("@LegacyId", entity.LegacyId);
                cmd.Parameters.AddWithValue("@OperatingContextTypeId", (int)entity.OperatingContextType);
                cmd.Parameters.AddWithValue("@ProviderTypeId", (int)entity.ProviderType);

                int operatingContextId = (int)cmd.ExecuteScalar();

                cmd.CommandText = "INSERT INTO AssociateOperatingContext (AssociateId, OperatingContextId) VALUES ( " +
                                  "@AssociateId, @OperatingContextId)";

                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@AssociateId", id);
                cmd.Parameters.AddWithValue("@OperatingContextId", operatingContextId);

                cmd.ExecuteNonQuery();

                cmd.Transaction.Commit();
            }
            catch (Exception)
            {
                cmd.Transaction.Rollback();

                throw;
            }
        }