public ExampleDataModel Insert(ExampleDataModel dataModel) // always do insert and update together. Check if it already exists, if so update, if not insert { try { using (AsignioDatabase db = new AsignioDatabase(ConnectionStringName)) { ExampleDataModel returnModel = GetFromID(dataModel.ExampleID); ExamplePoco poco = dataModel.ToPoco(); if (returnModel != null) { db.Update(poco); } else { poco.ExampleID = GuidMapper.Map(Guid.NewGuid()); poco.DateAdded = DateTime.Now; db.Insert(poco); } } } catch (Exception ex) { string errorMessage = ex.Message; } finally { } return(null); }
internal static ExamplePoco ToPoco(this ExampleDataModel source) { if (null != source) { return(new ExamplePoco { BoolValue = source.BoolValue, DateAdded = source.DateAdded, DoubleValue = source.DoubleValue, ExampleID = GuidMapper.Map(source.ExampleID), IntValue = source.IntValue, Name = source.Name, StringValue = source.StringValue, }); } return(null); }