/// <summary> /// Row (FieldID,data) representaion of the data /// /// </summary> private Dictionary <int, ContentFulRowData> ExtractRowData() { var data = new Dictionary <int, ContentFulRowData>(); int rowIndex = 2; bool EndOfRowFound = false; while (!EndOfRowFound) { ContentFulRowData rowData = new ContentFulRowData(); if (ContainsSysID) { rowData.SysID = GetCellData(rowIndex, SysIDIndex + 1); } foreach (var field in FieldIndexDictionary.Keys) { int index = FieldIndexDictionary[field]; string value = GetCellData(rowIndex, (index + 1)); rowData.FieldData.Add(field, value); } if (!rowData.IsAllDataEmpty) { data.Add(rowIndex, rowData); rowIndex++; } else { EndOfRowFound = true; } } return(data); }
public void LoadContentType(ContentTypeData contentType, ContentFulRowData rowData) { this.ContentType = contentType; this.RowData = rowData; LoadFields(); }
public void LoadContentType(ContentTypeData contentType) { this.ContentType = contentType; LoadFields(); RowData = null; }
private void btnSave_Click(object sender, EventArgs e) { var update = RowData != null; if (!update) { RowData = new ContentFulRowData(); RowData.FieldData = new Dictionary <string, string>(); foreach (var template in Templates) { var field = template.GetFieldValue(); RowData.FieldData.Add(field.Id, template.GetValue()); } string[] validationData = new string[0]; if (!RowData.ValidateRow(ContentType.ContentFullType.Fields.ToArray(), -1, out validationData)) { MessageBox.Show(this, string.Join(Environment.NewLine, validationData), "Failed Validation", MessageBoxButtons.OK, MessageBoxIcon.Error); RowData = null; return; } else { try { var entry = RowData.GetDynamicEntry(ContentType.ContentFullType.Fields.ToArray()); var result = Library.ContentFul.Client.Instance.AddContent(entry, ContentType.TypeID); var publishResult = Library.ContentFul.Client.Instance.PublishContent(result.SystemProperties.Id, result.SystemProperties.Version ?? 1); MessageBox.Show(this, "Data uploaded and published", "Uploaded", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception err) { var message = err.Message; if (err.InnerException != null) { message += Environment.NewLine + err.InnerException.Message; } MessageBox.Show(this, message, "Failed Validation", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } else { UpdateFieldDataToRows(); string[] validationData = new string[0]; if (!RowData.ValidateRow(ContentType.ContentFullType.Fields.ToArray(), -1, out validationData)) { MessageBox.Show(this, string.Join(Environment.NewLine, validationData), "Failed Validation", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { var entry = RowData.GetDynamicEntry(ContentType.ContentFullType.Fields.ToArray()); try { var result = Library.ContentFul.Client.Instance.UpdateContent(entry, ContentType.TypeID); MessageBox.Show(this, "Data updated", "Uploaded", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception err) { var message = err.Message; if (err.InnerException != null) { message += Environment.NewLine + err.InnerException.Message; } MessageBox.Show(this, err.Message, "Failed Validation", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } Library.ContentFul.Client.Instance.UpdateLanguageCountryVersion(); this.DialogResult = DialogResult.OK; this.Close(); }