public static void Save(BoardCertificationsAdminDetailView parent, SubEntity memberBoards) { try { memberBoards.ErrorMessage = string.Empty; //Edits foreach (var record in memberBoards.Records.Where(r => r.Action == RecordActions.Edited)) { var request = new UpdateCertificationBoardRequest { Id = int.Parse(parent.GetFieldValue(record.Fields, _id)), Name = parent.GetFieldValue(record.Fields, _boardName), IsEnabled = bool.Parse(parent.GetFieldValue(record.Fields, _boardEnabled)) }; parent.ProcessRequest<UpdateCertificationBoardResponse>(request); } //New Records Created foreach (var record in memberBoards.Records.Where(r => r.Action == RecordActions.New)) { var addBoardRequest = new AddCertificationBoardRequest { Name = parent.GetFieldValue(record.Fields, _boardName), IsEnabled = bool.Parse(parent.GetFieldValue(record.Fields, _boardEnabled)), CertificationAgencyId = int.Parse(parent.GetFieldValue(record.Fields, _agencyId)) }; parent.ProcessRequest<AddCertificationBoardResponse>(addBoardRequest); } } catch (Exception ex) { memberBoards.ErrorMessage = ex.Message; throw; } foreach (var record in memberBoards.Records) { //Update Subentities for Record foreach (var subentity in record.SubEntities) { if (subentity.EntityName == BoardCertificationsAdminDetailView._certificationSpecialtySubEntity) SaveCertificationSpecialties(parent, subentity, int.Parse(parent.GetFieldValue(record.Fields, _id))); } } }
private static SubEntity BuildCertificationSpecialtySubEntity(BoardCertificationsAdminDetailView parent, CertificationBoardDto boardDto) { var subEntity = new SubEntity() { EntityName = BoardCertificationsAdminDetailView._certificationSpecialtySubEntity, DisplayName = "Certification Specialties", CanCreateNew = true }; var request = new ListCertificationSpecialtiesRequest() { CertificationBoardId = boardDto.Id}; var response = parent.ProcessRequest<ListCertificationSpecialtiesResponse>(request); foreach (var specialty in response.CertificationSpecialties) { var record = new SubEntityRecord(); record.Fields.Add(new Field(_id, _specialtyId, FieldTypes.Hidden, specialty.Id)); record.Fields.Add(new Field(_boardId, _boardId, FieldTypes.Hidden, boardDto.Id)); record.Fields.Add(new Field(_specialtyName, "Name", FieldTypes.Text, specialty.Name, true)); record.Fields.Add(new Field(_specialtyEnabled, "Enabled", FieldTypes.Checkbox, specialty.IsEnabled)); record.Fields.Add(new Field(_isSubSpecialty, "Sub-Specialty", FieldTypes.Checkbox, specialty.IsSubspecialty)); subEntity.Records.Add(record); } subEntity.NewRecordTemplate.Fields.Add(new Field(_boardId, _boardId, FieldTypes.Hidden, boardDto.Id)); subEntity.NewRecordTemplate.Fields.Add(new Field(_specialtyName, "Name", FieldTypes.Text, string.Empty, true)); subEntity.NewRecordTemplate.Fields.Add(new Field(_specialtyEnabled, "Enabled", FieldTypes.Checkbox, true)); subEntity.NewRecordTemplate.Fields.Add(new Field(_isSubSpecialty, "Sub-Specialty", FieldTypes.Checkbox, false)); return subEntity; }
private static void SaveCertificationSpecialties(BoardCertificationsAdminDetailView parent, SubEntity subentity, int boardId) { foreach (var record in subentity.Records.Where(r => r.Action == RecordActions.Edited)) { var request = new UpdateCertificationSpecialtyRequest { Id = int.Parse(parent.GetFieldValue(record.Fields, _id)), Name = parent.GetFieldValue(record.Fields, _specialtyName), IsEnabled = bool.Parse(parent.GetFieldValue(record.Fields, _specialtyEnabled)), IsSubspecialty = bool.Parse(parent.GetFieldValue(record.Fields, _isSubSpecialty)), }; parent.ProcessRequest<UpdateCertificationSpecialtyResponse>(request); } foreach (var record in subentity.Records.Where(r => r.Action == RecordActions.New)) { var request = new AddCertificationSpecialtyRequest { CertificationBoardId = boardId, Name = parent.GetFieldValue(record.Fields, _specialtyName), IsEnabled = bool.Parse(parent.GetFieldValue(record.Fields, _specialtyEnabled)), IsSubspecialty = bool.Parse(parent.GetFieldValue(record.Fields, _isSubSpecialty)), }; parent.ProcessRequest<AddCertificationSpecialtyResponse>(request); } }
private static void AddExistingRecords(BoardCertificationsAdminDetailView parent, CertificationAgencyDto certificationAgencyDto) { var request = new ListCertificationBoardsRequest() { CertificationAgencyId = certificationAgencyDto.Id }; var boards = parent.ProcessRequest<ListCertificationBoardsResponse>(request).CertificationBoards; foreach (var board in boards) { var record = new SubEntityRecord(); var fields = new List<Field>(); fields.Add(new Field(_id, _id, FieldTypes.Hidden, board.Id)); fields.Add(new Field(_agencyId, _agencyId, FieldTypes.Hidden, board.CertificationAgencyId)); fields.Add(new Field(_boardName, "Name", FieldTypes.Text, board.Name, true)); fields.Add(new Field(_boardEnabled, "Enabled", FieldTypes.Checkbox, board.IsEnabled)); record.Fields = fields; record.SubEntities.Add(BuildCertificationSpecialtySubEntity(parent, board)); _subEntity.Records.Add(record); } }