public EditorElementItem(string tableName, string columnName, Type columnType) { name = columnName; label = TableKeys.GetColumnComment(tableName, columnName); var fkKey = TableKeys.GetColumnRelation(tableName, columnName); bool isFk = !string.IsNullOrEmpty(fkKey.columnName); view = getColumnEditType(columnType, isFk); if (isFk) { options = IdValueItem.getAll(NameDict.city, NameDict.name); } else { var maxLength = TableKeys.GetColumnMaxLength(tableName, columnName); if (maxLength > 0) { attributes = new AttributesItem(maxLength); pattern = PatternItem.getByType(columnType, maxLength); } } if (columnType == typeof(DateTime)) { timepicker = true; } }
public HttpResponseMessage Save(string entity) { var tableName = entity.ToUpper(); var body = Request.Content.ReadAsStringAsync().Result; var text = HttpUtility.UrlDecode(body); var table = TableManager.GetTable(tableName); text = text.IndexOf("data=") == 0 ? text.Remove(0, 5) : text; var obj = JsonConvert.DeserializeObject(text) as JObject; if (obj != null && CheckEntityForEdit(entity)) { var newRow = ParseResponse(obj, table.NewRow()); var isNew = false; if (isNew = newRow[NameDict.ID] == DBNull.Value) { newRow[NameDict.ID] = TableManager.GetNewId(tableName); } var id = newRow[NameDict.ID]; string message = null; try { if (isNew) { TableManager.InsertRow(newRow); } else { TableManager.UpdateRecord(TableManager.SelectRowByPrimaryKey(tableName, id), newRow); } message = AfterSave(newRow, obj, isNew); } catch (FbException ex) { if (ex.ErrorCode == 335544349) { var uniqColumns = TableKeys.GetUniqColumns(tableName).Select(t => TableKeys.GetColumnComment(tableName, t)).ToList(); message = "Violation of uniqueness by " + string.Join(", ", uniqColumns); } } if (message != null) { return(CreateResponse(HttpStatusCode.Conflict, message)); } return(CreateResponse(HttpStatusCode.OK, id)); } return(PrepareResponce(null)); }