private void Save()
        {
            _specialtyId = int.Parse(GetFieldValue(_viewModel.Fields, _id), CultureInfo.InvariantCulture);

            if (_specialtyId == 0)
            {
                var addRequest = new AddSpecialtyRequest();

                var nameValue = GetFieldValue(_viewModel.Fields, _name);
                addRequest.Name = nameValue;
                var isEnabledValue = GetFieldValue(_viewModel.Fields, _isEnabled);
                addRequest.IsEnabled = bool.Parse(isEnabledValue);
                var specialtyTypeValue = GetFieldValue(_viewModel.Fields, _specialtyType);
                addRequest.SpecialtyType = specialtyTypeValue;

                _specialtyId = ProcessRequest<AddSpecialtyResponse>(addRequest).Id;
            }
            else
            {
                if (_viewModel.Action == RecordActions.Edited)
                {
                    var updateRequest = new UpdateSpecialtyRequest();

                    updateRequest.Id = _specialtyId;
                    var nameValue = GetFieldValue(_viewModel.Fields, _name);
                    updateRequest.Name = nameValue;
                    var isEnabledValue = GetFieldValue(_viewModel.Fields, _isEnabled);
                    updateRequest.IsEnabled = bool.Parse(isEnabledValue);
                    var specialtyTypeValue = GetFieldValue(_viewModel.Fields, _specialtyType);
                    updateRequest.SpecialtyType = specialtyTypeValue;

                    ProcessRequest<UpdateSpecialtyResponse>(updateRequest);
                }
            }
        }
        public static void Save(ProviderAdminDetailView parent, SubEntity providerSpecialties, int providerId)
        {
            try
            {
                providerSpecialties.ErrorMessage = string.Empty;

                if (providerSpecialties.Records.Count(s => s.Fields.Any(f => f.FieldName == _isPrimary) && bool.Parse(parent.GetFieldValue(s.Fields, _isPrimary))) > 1)
                {
                    throw new BusinessException("Only one Provider Specialty can be set as the primary specialty");
                }

                //Edits
                foreach (var record in providerSpecialties.Records.Where(r => r.Action == RecordActions.Edited))
                {
                    if (parent.GetFieldValue(record.Fields, _specialtyType) == "Specialty")
                    {
                        var request = new UpdateProviderSpecialtyRequest();

                        request.Id = int.Parse(parent.GetFieldValue(record.Fields, _id));
                        request.IsPrimary = bool.Parse(parent.GetFieldValue(record.Fields, _isPrimary));
                        request.IsBoardCertified = bool.Parse(parent.GetFieldValue(record.Fields, _isBoardCertified));

                        parent.ProcessRequest<UpdateProviderSpecialtyResponse>(request);
                    }
                }

                //Existing Records Added
                foreach (var record in providerSpecialties.Records.Where(r => r.Action == RecordActions.Added))
                {
                    var request = new AddProviderSpecialtyRequest()
                    {
                        ProviderId = providerId,
                        SpecialtyId = int.Parse(parent.GetFieldValue(record.Fields, _specialtyId))
                    };

                    if (record.Fields.Any(f => f.FieldName == _isPrimary))
                        request.IsPrimary = bool.Parse(parent.GetFieldValue(record.Fields, _isPrimary));
                    if (record.Fields.Any(f => f.FieldName == _isBoardCertified))
                        request.IsBoardCertified = bool.Parse(parent.GetFieldValue(record.Fields, _isBoardCertified));

                    parent.ProcessRequest<AddProviderSpecialtyResponse>(request);
                }

                //New Records Created
                foreach (var record in providerSpecialties.Records.Where(r => r.Action == RecordActions.New))
                {
                    //Add New Specialty/Condition
                    var addSpecialtyRequest = new AddSpecialtyRequest()
                    {
                        Name = parent.GetFieldValue(record.Fields, _name),
                        SpecialtyType = parent.GetFieldValue(record.Fields, _specialtyType),
                        IsEnabled = true
                    };
                    var addedSpecialtyId = parent.ProcessRequest<AddSpecialtyResponse>(addSpecialtyRequest).Id;

                    //Add newly created specialty to provider
                    var request = new AddProviderSpecialtyRequest()
                    {
                        ProviderId = providerId,
                        SpecialtyId = addedSpecialtyId
                    };

                    if (addSpecialtyRequest.SpecialtyType == "Specialty")
                    {
                        request.IsPrimary = bool.Parse(parent.GetFieldValue(record.Fields, _isPrimary));
                        request.IsBoardCertified = bool.Parse(parent.GetFieldValue(record.Fields, _isBoardCertified));
                    }

                    parent.ProcessRequest<AddProviderSpecialtyResponse>(request);
                }

                //Records Deleted
                foreach (var record in providerSpecialties.Records.Where(r => r.Action == RecordActions.Deleted))
                {
                    var request = new DeleteProviderSpecialtyRequest()
                    {
                        ProviderId = int.Parse(parent.GetFieldValue(record.Fields, _providerId)),
                        SpecialtyId = int.Parse(parent.GetFieldValue(record.Fields, _specialtyId))
                    };
                    parent.ProcessRequest<DeleteProviderSpecialtyResponse>(request);
                }
            }
            catch (Exception ex)
            {
                providerSpecialties.ErrorMessage = ex.Message;
                throw;
            }

            providerSpecialties = BuildSpecialtiesSubEntity(parent, providerId);
        }