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); }
public void GetProperty_InvalidStringValue_ReturnsInvalid(string stringValue) { var item = new GuidMapper(); object value = 1; PropertyMapperResultType result = item.MapCellValue(new ReadCellValueResult(-1, stringValue), ref value); Assert.Equal(PropertyMapperResultType.Invalid, result); Assert.Equal(1, value); }
public void GetProperty_ValidStringValue_ReturnsSuccess(string stringValue, Guid expected) { var item = new GuidMapper(); object value = null; PropertyMapperResultType result = item.MapCellValue(new ReadCellValueResult(-1, stringValue), ref value); Assert.Equal(PropertyMapperResultType.Success, result); Assert.Equal(expected, value); }
internal static UserDataModel ToModel(this UserPoco source) { if (null != source) { return(new UserDataModel { EmailAddress = source.EmailAddress, UserID = GuidMapper.Map(source.UserID), }); } return(null); }
internal static LogWebRequestDataModel ToModel(this LogWebRequestPoco source) { if (null != source) { return(new LogWebRequestDataModel { TimeStamp = source.TimeStamp, WebRequestID = GuidMapper.Map(source.WebRequestID), UserID = GuidMapper.Map(source.UserID), RawURL = source.RawURL, Parameters = source.Parameters, Important = source.Important, }); } return(null); }
internal static LogControllerActionDataModel ToModel(this LogControllerActionPoco source) { if (null != source) { return(new LogControllerActionDataModel { TimeStamp = source.TimeStamp, WebRequestID = GuidMapper.Map(source.WebRequestID), UserID = GuidMapper.Map(source.UserID), ControllerName = source.ControllerName, ActionName = source.ActionName, Parameters = source.Parameters, }); } return(null); }
internal static LogWebResponseDataModel ToModel(this LogWebResponsePoco source) { if (null != source) { return(new LogWebResponseDataModel { TimeStamp = source.TimeStamp, WebRequestID = GuidMapper.Map(source.WebRequestID), UserID = GuidMapper.Map(source.UserID), Status = source.Status, StatusCode = source.StatusCode, StatusDescription = source.StatusDescription, RedirectLocation = source.RedirectLocation, }); } return(null); }
internal static LogDataModel ToModel(this LogPoco source) { if (null != source) { return(new LogDataModel { TimeStamp = source.TimeStamp, LogID = GuidMapper.Map(source.LogID), UserID = GuidMapper.Map(source.UserID), Message = source.Message, Username = source.Username, Source = source.Source, Level = source.Level, }); } return(null); }
internal static LogInfoDataModel ToModel(this LogInfoPoco source) { if (null != source) { return(new LogInfoDataModel { TimeStamp = source.TimeStamp, WebRequestID = GuidMapper.Map(source.WebRequestID), UserID = GuidMapper.Map(source.UserID), Message = source.Message, MethodName = source.MethodName, Object = source.Object, ID = GuidMapper.Map(source.ID), }); } return(null); }
internal static LogExceptionDataModel ToModel(this LogExceptionPoco source) { if (null != source) { return(new LogExceptionDataModel { TimeStamp = source.TimeStamp, WebRequestID = GuidMapper.Map(source.WebRequestID), UserID = GuidMapper.Map(source.UserID), Message = source.Message, MethodName = source.MethodName, Source = source.Source, StackTrace = source.StackTrace, }); } return(null); }
internal static CombinedLogWebResponseDataModel ToModel(this CombinedLogWebResponsePoco source) { if (null != source) { return(new CombinedLogWebResponseDataModel { EmailAddress = source.EmailAddress, TimeStamp = source.TimeStamp, WebRequestID = GuidMapper.Map(source.WebRequestID), Status = source.Status, RedirectLocation = source.RedirectLocation, UserID = GuidMapper.Map(source.UserID), Important = source.Important, }); } return(null); }
internal static CombinedLogDataModel ToModel(this CombinedLogPoco source) { if (null != source) { return(new CombinedLogDataModel { UserID = GuidMapper.Map(source.UserID), EmailAddress = source.EmailAddress, TimeStamp = source.TimeStamp, LogID = GuidMapper.Map(source.LogID), Message = source.Message, Level = source.Level, Source = source.Source, Important = source.Important, }); } return(null); }
internal static ExampleDataModel ToModel(this ExamplePoco source) { if (null != source) { return(new ExampleDataModel { 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); }
internal static CombinedLogControllerActionDataModel ToModel(this CombinedLogControllerActionPoco source) { if (null != source) { return(new CombinedLogControllerActionDataModel { EmailAddress = source.EmailAddress, TimeStamp = source.TimeStamp, WebRequestID = GuidMapper.Map(source.WebRequestID), ControllerName = source.ControllerName, ActionName = source.ActionName, Parameters = source.Parameters, UserID = GuidMapper.Map(source.UserID), Important = source.Important, }); } return(null); }
internal static CombinedLogExceptionDataModel ToModel(this CombinedLogExceptionPoco source) { if (null != source) { return(new CombinedLogExceptionDataModel { UserID = GuidMapper.Map(source.UserID), EmailAddress = source.EmailAddress, TimeStamp = source.TimeStamp, WebRequestID = GuidMapper.Map(source.WebRequestID), Message = source.Message, MethodName = source.MethodName, Source = source.Source, StackTrace = source.StackTrace, Important = source.Important, }); } return(null); }
internal static CombinedLogInfoDataModel ToModel(this CombinedLogInfoPoco source) { if (null != source) { return(new CombinedLogInfoDataModel { EmailAddress = source.EmailAddress, TimeStamp = source.TimeStamp, WebRequestID = GuidMapper.Map(source.WebRequestID), Message = source.Message, MethodName = source.MethodName, Object = source.Object, UserID = GuidMapper.Map(source.UserID), Important = source.Important, }); } return(null); }
private static bool TryGetWellKnownMap(Type memberType, FallbackStrategy emptyValueStrategy, out ICellValueMapper mapper, out IFallbackItem emptyFallback, out IFallbackItem invalidFallback) { Type type = memberType.GetNullableTypeOrThis(out bool isNullable); Type[] interfaces = type.GetTypeInfo().ImplementedInterfaces.ToArray(); IFallbackItem ReconcileFallback(FallbackStrategy strategyToPursue, bool isEmpty) { // Empty nullable values should be set to null. if (isEmpty && isNullable) { return(new FixedValueFallback(null)); } else if (strategyToPursue == FallbackStrategy.SetToDefaultValue || emptyValueStrategy == FallbackStrategy.SetToDefaultValue) { return(new FixedValueFallback(type.DefaultValue())); } else { Debug.Assert(emptyValueStrategy == FallbackStrategy.ThrowIfPrimitive); // The user specified that we should set to the default value if it was empty. return(new ThrowFallback()); } } // Set the default mapper for each well-known type. if (type == typeof(DateTime)) { mapper = new DateTimeMapper(); emptyFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, isEmpty: true); invalidFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, isEmpty: false); } else if (type == typeof(Guid)) { mapper = new GuidMapper(); emptyFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, isEmpty: true); invalidFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, isEmpty: false); } else if (type == typeof(bool)) { mapper = new BoolMapper(); emptyFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, isEmpty: true); invalidFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, isEmpty: false); } else if (type.GetTypeInfo().IsEnum) { mapper = new EnumMapper(type); emptyFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, isEmpty: true); invalidFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, isEmpty: false); } else if (type == typeof(string) || type == typeof(object) || type == typeof(IConvertible)) { mapper = new StringMapper(); emptyFallback = ReconcileFallback(FallbackStrategy.SetToDefaultValue, isEmpty: true); invalidFallback = ReconcileFallback(FallbackStrategy.SetToDefaultValue, isEmpty: false); } else if (type == typeof(Uri)) { mapper = new UriMapper(); emptyFallback = ReconcileFallback(FallbackStrategy.SetToDefaultValue, isEmpty: true); invalidFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, isEmpty: false); } else if (interfaces.Any(t => t == typeof(IConvertible))) { mapper = new ChangeTypeMapper(type); emptyFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, isEmpty: true); invalidFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, isEmpty: false); } else { mapper = null; emptyFallback = null; invalidFallback = null; return(false); } return(true); }
//public ExampleRepository(string connectionStringName) // : base(typeof(ExampleRepository), connectionStringName) //{ } public ExampleDataModel GetFromID(Guid ExampleID) { try { using (AsignioDatabase db = new AsignioDatabase(ConnectionStringName)) { return(db.FirstOrDefault <ExamplePoco>(ExamplePoco.SelectByIDSQL, GuidMapper.Map(ExampleID)).ToModel()); } } catch (Exception ex) { string errorMessage = ex.Message; } finally { } return(null); }