/// <summary> /// 重载此方法加入添加日志 /// </summary> /// <param name="value"></param> /// <param name="msg"></param> /// <returns></returns> public override bool Add(T value, out string msg) { try { msg = string.Empty; if (value != null) { ILEntity lEntity = value as ILEntity; Guid userId = ConnectedUserId; if (lEntity != null) { var now = DateTime.Now; lEntity.CreateTime = now; lEntity.CreateUserId = userId == Guid.Empty ? CurrentStore.Id : userId; lEntity.UpdateTime = now; lEntity.UpdateUserId = lEntity.CreateUserId; } //FixTime var propertyInfos = typeof(T).GetProperties().Where(t => t.PropertyType == typeof(DateTime)); foreach (var propertyInfo in propertyInfos) { var obj = propertyInfo.GetValue(value, null); bool needTime = false; if (obj != null) { var oldTime = (DateTime)obj; needTime = (oldTime == default(DateTime)); } if (needTime) { propertyInfo.SetValue(value, DateTime.Now, null); log.Warning(string.Format("FixTime:{0}.{1}", typeof(T).FullName, propertyInfo.Name)); } } //FixTime bool addOK = base.Add(value, out msg); // if (!(value is UserLog)) //{ // //加条日志 // BusinessHandlerFactory.UserLogBusinessHandler.LogUserLog(new UserLog // { // Content = string.Format("编号为{0}的用户添加并提交[{1}]:{2}", userId, value.ToJson(), addOK) // }); //} return(addOK); } else { msg = string.Format("添加的实体[{0}]不可为null", EntityName); Log.Warning(msg); return(false); } } catch (Exception ex) { msg = string.Format("添加实体{0}并提交出错", EntityName); return(this.HandleException <bool>(msg, ex)); } }
/// <summary> /// 重载此方法加入添加日志 /// </summary> /// <param name="value"></param> public override void Add(T value) { try { if (value != null) { Guid userId = ConnectedUserId; List <User> userList = RepositoryProvider.Db.Users.ToList(); Guid roleGuid = RepositoryProvider.Db.Roles.Where(r => r.Name.Contains("SystemRole")).FirstOrDefault().Id; List <RoleWithUser> RoleWList = RepositoryProvider.Db.RoleWithUsers.Where(r => r.RoleId.Equals(roleGuid)).ToList(); var u = from i in RoleWList join k in userList on i.UserId equals k.Id select k; userList = u.ToList(); Guid SysRoleId = userList.First().Id; ILEntity lEntity = value as ILEntity; if (lEntity != null) { var now = DateTime.Now; lEntity.CreateTime = now; lEntity.CreateUserId = lEntity.CreateUserId == Guid.Empty ? SysRoleId : lEntity.CreateUserId; lEntity.UpdateTime = now; lEntity.UpdateUserId = lEntity.CreateUserId == Guid.Empty ? SysRoleId : lEntity.CreateUserId; } //FixTime var propertyInfos = typeof(T).GetProperties().Where(t => t.PropertyType == typeof(DateTime)); foreach (var propertyInfo in propertyInfos) { var obj = propertyInfo.GetValue(value, null); bool needTime = false; if (obj != null) { var oldTime = (DateTime)obj; needTime = (oldTime == default(DateTime)); } if (needTime) { propertyInfo.SetValue(value, DateTime.Now, null); log.Warning(string.Format("FixTime:{0}.{1}", typeof(T).FullName, propertyInfo.Name)); } } //FixTime base.Add(value); //if (!(value is UserLog)) //{ // BusinessHandlerFactory.UserLogBusinessHandler.LogUserLog(new UserLog // { // Content = string.Format("编号为{0}的用户添加[{1}].", userId, value.ToJson()) // }); //} } } catch (Exception ex) { this.HandleException(string.Format("添加实体{0}不提交出错", EntityName), ex); } }
/// <summary> /// 保存对象不提交 /// </summary> public override void Save(T value) { try { if (value != null) { Guid userId = ConnectedUserId; ILEntity lEntity = value as ILEntity; if (lEntity != null) { var now = DateTime.Now; lEntity.UpdateTime = now; lEntity.UpdateUserId = userId == Guid.Empty ? CurrentStore.Id : userId; lEntity.UpdateTime = now; } //FixTime var propertyInfos = typeof(T).GetProperties().Where(t => t.PropertyType == typeof(DateTime)); foreach (var propertyInfo in propertyInfos) { var obj = propertyInfo.GetValue(value, null); bool needTime = false; if (obj != null) { var oldTime = (DateTime)obj; needTime = (oldTime == default(DateTime)); } if (needTime) { propertyInfo.SetValue(value, DateTime.Now, null); log.Warning(string.Format("FixTime:{0}.{1}", typeof(T).FullName, propertyInfo.Name)); } } //FixTime base.Save(value); //if (!(value is UserLog)) //{ // BusinessHandlerFactory.UserLogBusinessHandler.LogUserLog(new UserLog // { // Content = string.Format("编号为{0}的用户修改数据[{1}]:{2}", userId, value.Id, value.ToJson()) // }); //} } } catch (Exception ex) { this.HandleException(string.Format("保存实体{0}不提交出错", EntityName), ex); } }