internal static TBiz SaveAsUser <TBiz, TDal>(TBiz item, int userId) where TDal : D.EntityObject, IQpEntityObject where TBiz : EntityObject { var entities = QPContext.EFContext; var dalItem = DefaultMapper.GetDalObject <TDal, TBiz>(item); if (item.ForceId != 0) { dalItem.Id = item.ForceId; } DateTime current; using (new QPConnectionScope()) { current = Common.GetSqlDate(QPConnectionScope.Current.DbConnection); } dalItem.Created = current; dalItem.Modified = current; dalItem.LastModifiedBy = userId; entities.AddObject(GetSetNameByType(typeof(TDal)), dalItem); entities.SaveChanges(); return(DefaultMapper.GetBizObject <TBiz, TDal>(dalItem)); }
internal static TBiz Update <TBiz, TDal>(TBiz item) where TDal : class, IQpEntityObject where TBiz : EntityObject { var dalItem = DefaultMapper.GetDalObject <TDal, TBiz>(item); var entities = QPContext.EFContext; dalItem.LastModifiedBy = QPContext.CurrentUserId; using (new QPConnectionScope()) { dalItem.Modified = Common.GetSqlDate(QPConnectionScope.Current.DbConnection); } entities.Entry(dalItem).State = EntityState.Modified; entities.SaveChanges(); return(DefaultMapper.GetBizObject <TBiz, TDal>(dalItem)); }
internal static TBiz Update <TBiz, TDal>(TBiz item) where TDal : D.EntityObject, IQpEntityObject where TBiz : EntityObject { var dalItem = DefaultMapper.GetDalObject <TDal, TBiz>(item); var entities = QPContext.EFContext; dalItem.LastModifiedBy = QPContext.CurrentUserId; using (new QPConnectionScope()) { dalItem.Modified = Common.GetSqlDate(QPConnectionScope.Current.DbConnection); } entities.AttachTo(GetSetNameByType(typeof(TDal)), dalItem); entities.ObjectStateManager.ChangeObjectState(dalItem, EntityState.Modified); entities.SaveChanges(); return(DefaultMapper.GetBizObject <TBiz, TDal>(dalItem)); }