コード例 #1
0
ファイル: DefaultRepository.cs プロジェクト: AuthorProxy/QP
        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));
        }
コード例 #2
0
ファイル: DefaultRepository.cs プロジェクト: QuantumArt/QP
        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));
        }
コード例 #3
0
ファイル: DefaultRepository.cs プロジェクト: AuthorProxy/QP
        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));
        }