예제 #1
0
        public Task <CertificationRM> GetCertificationForOperatingContext(int associateId, int operatingContextId,
                                                                          int certificationId)
        {
            ValidateAssociateExists(associateId);
            OperatingContext operatingContext = ValidateOperatingContextExists(operatingContextId);

            return(Task.FromResult(_mapper.Map <Certification, CertificationRM>(
                                       _context.Certifications.SingleOrDefault(c => c.Id == operatingContext.CertificationId && c.Id == certificationId))));
        }
        public async void AddAssociateOperatingContext(Associate associate, OperatingContext operatingContext)
        {
            int operatingContextId = _context.OperatingContexts.ToList().Last().Id;

            AssociateOperatingContext association = new AssociateOperatingContext(associate.Id, operatingContextId);

            _context.AssociateOperatingContexts.Add(association);

            await _context.SaveChangesAsync();
        }
        private void UpdateOperatingContext(Commands.V1.OperatingContext.Update cmd)
        {
            OperatingContext operatingContext = _repository.GetOperatingContext(cmd.OperatingContextId);

            if (operatingContext == null)
            {
                throw new InvalidOperationException($"OperatingContext with id {cmd.OperatingContextId} cannot be found");
            }

            _repository.UpdateOperatingContext(operatingContext);
        }
        public bool CertificationExistsForOperatingContext(Certification certification, int operatingContextId)
        {
            OperatingContext operatingContext =
                _context.OperatingContexts.FirstOrDefault(oc => oc.Id == operatingContextId);

            if (operatingContext == null)
            {
                return(false);
            }

            return(operatingContext.CertificationId != null);
        }
        public void AddCertificationForOperatingContext(Certification certification, int operatingContextId)
        {
            OperatingContext operatingContext =
                _context.OperatingContexts.SingleOrDefault(oc => oc.Id == operatingContextId);

            if (operatingContext == null)
            {
                throw new InvalidOperationException("OperatingContext not found.");
            }

            operatingContext.Certification = certification;
        }
예제 #6
0
        private OperatingContext ValidateOperatingContextExists(int operatingContextId)
        {
            OperatingContext operatingContext =
                _context.OperatingContexts.SingleOrDefault(a => a.Id == operatingContextId);

            if (operatingContext == null)
            {
                throw new InvalidOperationException("OperatingContext not found.");
            }

            return(operatingContext);
        }
        private OperatingContextRM CreateOperatingContextForCustomer(Commands.V1.OperatingContext.CreateForCustomer cmd)
        {
            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]);

            if (_repository.OperatingContextExistsForCustomer(operatingContext, cmd.CustomerId))
            {
                throw new InvalidOperationException($"Operating context already exists for Customer {cmd.CustomerId}");
            }

            _repository.AddOperatingContextForCustomer(operatingContext, cmd.CustomerId);

            return(Conversions.GetOperatingContextRM(operatingContext));
        }
        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));
        }
예제 #9
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;
            }
        }
예제 #10
0
        public static OperatingContextRM GetOperatingContextRM(OperatingContext operatingContext)
        {
            // ReSharper disable once UseObjectOrCollectionInitializer
            OperatingContextRM operatingContextRM = new OperatingContextRM();

            operatingContextRM.Id                   = operatingContext.Id;
            operatingContextRM.ActingBAType         = operatingContext.ActingBATypeId;
            operatingContextRM.CertificationId      = operatingContext.CertificationId;
            operatingContextRM.FacilityId           = operatingContext.FacilityId;
            operatingContextRM.IsDeactivating       = operatingContext.IsDeactivating;
            operatingContextRM.LegacyId             = operatingContext.LegacyId;
            operatingContextRM.OperatingContextType = operatingContext.OperatingContextTypeId;
            operatingContextRM.PrimaryAddress       = operatingContext.PrimaryAddressId;
            operatingContextRM.PrimaryEmail         = operatingContext.PrimaryEmailId;
            operatingContextRM.PrimaryPhone         = operatingContext.PrimaryPhoneId;
            operatingContextRM.ProviderType         = operatingContext.ProviderTypeId;
            operatingContextRM.StartDate            = operatingContext.StartDate;
            operatingContextRM.Status               = operatingContext.StatusCodeId;
            operatingContextRM.ThirdPartySupplierId = operatingContext.ThirdPartySupplierId;

            return(operatingContextRM);
        }
        public void AddOperatingContextForAssociate(OperatingContext operatingContext, int associateId)
        {
            try
            {
                _context.OperatingContexts.Add(operatingContext);

                _context.AssociateOperatingContexts.Add(new AssociateOperatingContext
                {
                    OperatingContextId = operatingContext.Id,
                    AssociateId        = associateId
                });
            }
            catch
            {
                OperatingContext toRemove = _context.OperatingContexts.SingleOrDefault(oc => oc.Id == operatingContext.Id);

                if (toRemove != null)
                {
                    _context.OperatingContexts.Remove(toRemove);
                }

                throw;
            }
        }
 public void AddOperatingContextForCustomer(OperatingContext operatingContext, int customerId)
 {
     _context.OperatingContextCustomers.Add(new OperatingContextCustomer(customerId, operatingContext.Id));
 }
 public void AddOperatingContext(OperatingContext operatingContext)
 {
     _context.OperatingContexts.Add(operatingContext);
     _context.SaveChanges();
 }
 public void UpdateOperatingContext(OperatingContext operatingContext)
 {
     _context.OperatingContexts[operatingContext.Id] = operatingContext;
 }
 public bool OperatingContextExistsForAssociate(OperatingContext operatingContext, int associateId)
 {
     return(_context.AssociateOperatingContexts.Exists(aoc => aoc.AssociateId == associateId && aoc.AssociateId == associateId));
 }
 public bool OperatingContextExistsForCustomer(OperatingContext operatingContext, int customerId)
 {
     return(_context.OperatingContextCustomers.Exists(occ => occ.OperatingContextId == operatingContext.Id && occ.CustomerId == customerId));
 }
 public void AddOperatingContext(OperatingContext operatingContext)
 {
     _context.OperatingContexts.Add(operatingContext);
 }