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

            if (_languageId == 0)
            {
                var addRequest = new AddLanguageRequest();

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

                _languageId = ProcessRequest<AddLanguageResponse>(addRequest).Id;
            }
            else
            {
                if (_viewModel.Action == RecordActions.Edited)
                {
                    var updateRequest = new UpdateLanguageRequest();

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

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

                if (providerLanguages.Records.Count(s => bool.Parse(parent.GetFieldValue(s.Fields, _isPrimary))) > 1)
                {
                    throw new BusinessException("Only one Provider Language can be set as the primary language");
                }

                //Edits
                foreach (var record in providerLanguages.Records.Where(r => r.Action == RecordActions.Edited))
                {
                    var request = new UpdateProviderLanguageRequest();

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

                    parent.ProcessRequest<UpdateProviderLanguageResponse>(request);
                }

                //Existing Records Added
                foreach (var record in providerLanguages.Records.Where(r => r.Action == RecordActions.Added))
                {
                    var request = new AddProviderLanguageRequest()
                    {
                        ProviderId = providerId,
                        LanguageId = int.Parse(parent.GetFieldValue(record.Fields, _languageId)),
                        IsPrimary = bool.Parse(parent.GetFieldValue(record.Fields, _isPrimary)),
                        IsFluent = bool.Parse(parent.GetFieldValue(record.Fields, _isFluent))
                    };

                    parent.ProcessRequest<AddProviderLanguageResponse>(request);
                }

                //New Records Created
                foreach (var record in providerLanguages.Records.Where(r => r.Action == RecordActions.New))
                {
                    //Add New Language
                    var addLanguageRequest = new AddLanguageRequest()
                    {
                        Name = parent.GetFieldValue(record.Fields, _languageName),
                        IsEnabled = true
                    };
                    var addedLanguageId = parent.ProcessRequest<AddLanguageResponse>(addLanguageRequest).Id;

                    //Add newly created language to provider
                    var request = new AddProviderLanguageRequest()
                    {
                        ProviderId = providerId,
                        LanguageId = addedLanguageId,
                        IsPrimary = bool.Parse(parent.GetFieldValue(record.Fields, _isPrimary)),
                        IsFluent = bool.Parse(parent.GetFieldValue(record.Fields, _isFluent))
                    };

                    parent.ProcessRequest<AddProviderLanguageResponse>(request);
                }

                //Deletes
                foreach (var record in providerLanguages.Records.Where(r => r.Action == RecordActions.Deleted))
                {
                    var request = new DeleteProviderLanguageRequest()
                    {
                        ProviderId = providerId,
                        LanguageId = int.Parse(parent.GetFieldValue(record.Fields, _languageId))
                    };
                    parent.ProcessRequest<DeleteProviderLanguageResponse>(request);
                }
            }
            catch (Exception ex)
            {
                providerLanguages.ErrorMessage = ex.Message;
                throw;
            }

            providerLanguages = BuildLanguagesSubEntity(parent, providerId);
        }