public void updates_just_yearOfIssuance_provider_CertificationSpecialty()
        {
            //setup
            var request = new UpdateProviderCertificationSpecialtyRequest();
            request.Id = _existingProviderCertificationSpecialtyId;
            request.ProviderId = _providerIdWithCertificationSpecialty;
            request.CertificationSpecialtyId = _currentCertificationSpecialtyId;
            request.YearOfIssuance = "2000";
            var handler = CreateHandler();

            //act
            var response = HandleRequest<UpdateProviderCertificationSpecialtyResponse>(handler, request);

            //assert
            Assert.IsFalse(response.HasErrors);
            using (var context = _objectContextFactory.CreateObjectContext())
            {
                context.ContextOptions.LazyLoadingEnabled = true;
                context.ContextOptions.ProxyCreationEnabled = true;
                var provider = context.CreateObjectSet<Provider>().Single(p => p.Id == _providerIdWithCertificationSpecialty);

                var providerCertificationSpecialty = provider.ProviderCertificationSpecialties.Single(pe => pe.Id == _existingProviderCertificationSpecialtyId);
                Assert.AreEqual(request.CertificationSpecialtyId, providerCertificationSpecialty.CertificationSpecialty.Id);
                Assert.AreEqual(request.YearOfIssuance, providerCertificationSpecialty.YearOfIssuance);
            }
        }
        public void updates_provider_CertificationSpecialty_with_previously_associated_specialty()
        {
            //setup
            var request = new UpdateProviderCertificationSpecialtyRequest();
            request.Id = _existingProviderCertificationSpecialtyId;
            request.ProviderId = _providerIdWithCertificationSpecialty;
            request.CertificationSpecialtyId = _preexistingCertificationSpecialtyId;
            request.YearOfIssuance = "2000";
            var handler = CreateHandler();

            //act
            var response = HandleRequest<UpdateProviderCertificationSpecialtyResponse>(handler, request);

            //assert
            Assert.IsTrue(response.HasErrors);
            Console.WriteLine(response.ErrorsAsString());
            using (var context = _objectContextFactory.CreateObjectContext())
            {
                context.ContextOptions.LazyLoadingEnabled = true;
                context.ContextOptions.ProxyCreationEnabled = true;
                var provider = context.CreateObjectSet<Provider>().Single(p => p.Id == _providerIdWithCertificationSpecialty);

                var providerCertificationSpecialty = provider.ProviderCertificationSpecialties.Single(pe => pe.Id == _existingProviderCertificationSpecialtyId);
                Assert.AreNotEqual(request.YearOfIssuance, providerCertificationSpecialty.YearOfIssuance);
                Assert.AreNotEqual(request.CertificationSpecialtyId, providerCertificationSpecialty.CertificationSpecialty.Id);
            }
        }
コード例 #3
0
        public static void Save(ProviderAdminDetailView parent, SubEntity providerCertificationSpecialties, int providerId)
        {
            try
            {
                providerCertificationSpecialties.ErrorMessage = string.Empty;

                //Edits
                foreach (var record in providerCertificationSpecialties.Records.Where(r => r.Action == RecordActions.Edited))
                {
                    var yearOfIssuance = Validate(parent, record);

                    var request = new UpdateProviderCertificationSpecialtyRequest();

                    request.Id = int.Parse(parent.GetFieldValue(record.Fields, _id));
                    request.ProviderId = providerId;
                    request.CertificationSpecialtyId = int.Parse(parent.GetFieldValue(record.Fields, _certificationSpecialtyId));
                    request.YearOfIssuance = yearOfIssuance;

                    parent.ProcessRequest<UpdateProviderCertificationSpecialtyResponse>(request);
                }

                //Existing Records Added
                foreach (var record in providerCertificationSpecialties.Records.Where(r => r.Action == RecordActions.Added))
                {
                    var yearOfIssuance = Validate(parent, record);

                    var request = new AddProviderCertificationSpecialtyRequest()
                    {
                        ProviderId = providerId,
                        CertificationSpecialtyId = int.Parse(parent.GetFieldValue(record.Fields, _certificationSpecialtyId)),
                        YearOfIssuance = yearOfIssuance
                    };

                    parent.ProcessRequest<AddProviderCertificationSpecialtyResponse>(request);
                }

                //Deletes
                foreach (var record in providerCertificationSpecialties.Records.Where(r => r.Action == RecordActions.Deleted))
                {
                    var request = new DeleteProviderCertificationSpecialtyRequest()
                    {
                        ProviderId = providerId,
                        CertificationSpecialtyId = int.Parse(parent.GetFieldValue(record.Fields, _certificationSpecialtyId))
                    };
                    parent.ProcessRequest<DeleteProviderCertificationSpecialtyResponse>(request);
                }
            }
            catch (Exception ex)
            {
                providerCertificationSpecialties.ErrorMessage = ex.Message;
                throw;
            }

            providerCertificationSpecialties = BuildCertificationSubEntity(parent, providerId);
        }
 private UpdateProviderCertificationSpecialtyRequest CreateRequest()
 {
     var request = new UpdateProviderCertificationSpecialtyRequest();
     request.Id = _existingProviderCertificationSpecialtyId;
     request.ProviderId = _providerIdWithCertificationSpecialty;
     request.CertificationSpecialtyId = _newCertificationSpecialtyId;
     request.YearOfIssuance = "2000";
     return request;
 }