/// <summary> /// Converts an instance of tbKeywordRow to a 'real' Keyword object. /// </summary> /// <param name="KeywordRow">A single instance of tbKeywordRow to parse into a Keyword object.</param> /// <returns>A new Keyword object with properties set to the values in the row.</returns> public static Keyword MapRowToKeyword(DSNyMPH.tbKeywordRow KeywordRow) { Keyword _new = new Keyword(); //check for null row, then map fields to object if (KeywordRow != null) { _new.OID = KeywordRow.KeywordOID; _new.Name = KeywordRow.KeywordName; _new.IsCustom = KeywordRow.IsCustom; _new.KeywordType = ParseSDK(KeywordRow.KeywordType); } return(_new); }
/// <summary> /// Persists an instance of Keyword to the database. /// </summary> /// <param name="Item">A Keyword instance to add or update. If added, this Keyword will have its OID property assigned.</param> /// <returns>The number of rows affected; this will be -1 if an exception occurs.</returns> public int SaveKeyword(ref Keyword Item) { int _result = 0; if (Item != null) { //create typed data objects DSNyMPH.tbKeywordDataTable _dtKeyword = new DSNyMPH.tbKeywordDataTable(); try { using (tbKeywordTableAdapter _taKeyword = new tbKeywordTableAdapter()) { //fill typed table with instance(s) of this Keyword _taKeyword.FillByOID(_dtKeyword, Item.OID); //If no records are returned, add this Keyword to the datatable. if (_dtKeyword.Count == 0) { //add new row //_result = _taKeyword.Insert(Item.Name, Item.IsCustom, Item.KeywordType.ToString()); DSNyMPH.tbKeywordRow _row = _dtKeyword.NewtbKeywordRow(); //TODO: review this process //set properties _row.KeywordName = Item.Name; _row.KeywordType = Item.KeywordType.ToString(); _row.IsCustom = Item.IsCustom; _dtKeyword.AddtbKeywordRow(_row); //update changes to datatable using table adapter _result = _taKeyword.Update(_dtKeyword); Item.OID = FindKeywordOID(Item); } else { //should only be one instance //TODO: there's probably a better way to do this... DSNyMPH.tbKeywordRow _row = (DSNyMPH.tbKeywordRow)_dtKeyword.Rows[0]; //TODO: review this process //set properties _row.KeywordName = Item.Name; _row.KeywordType = Item.KeywordType.ToString(); _row.IsCustom = Item.IsCustom; //update changes to datatable using table adapter _result = _taKeyword.Update(_dtKeyword); } } } catch (Exception ex) { //write to logging _elh.WriteEvent(string.Format("Exception occurred while saving Keyword {0}. Exception details: {1}", Item.ToString(), ex.Message), EventLogEntryType.Error); _result = -1; } } else { _result = -1; } return(_result); }