/// <summary>
 /// 转换成对应的数据模型
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="listTemplateBlockItem"></param>
 /// <returns></returns>
 public static T ToViewModel <T>(this TemplateBlcokItem item) where T : IBlockItemViewModel
 {
     //反序列化对应的对象
     return(JsonConvert.DeserializeObject <T>(item.sContent, new JsonSerializerSettings
     {
         ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
         MissingMemberHandling = MissingMemberHandling.Ignore,
         NullValueHandling = NullValueHandling.Ignore,
         DefaultValueHandling = DefaultValueHandling.Ignore,
     }));
 }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public int AddOneBlockItem(int iTemplateID, int iTemplateBlcokID, IBlockItemViewModel viewModel)
        {
            var blockItem = new TemplateBlcokItem();

            blockItem.dAddTime         = DateTime.Now;
            blockItem.dupdateTime      = DateTime.Now;
            blockItem.iAction          = 0;
            blockItem.iOrder           = 1;
            blockItem.iTemplateBlcokID = iTemplateBlcokID;
            blockItem.iTemplateID      = iTemplateID;
            blockItem.sRemark          = string.Empty;
            blockItem.sContent         = JsonConvert.SerializeObject(viewModel);
            //
            DataContext.TemplateBlcokItems.InsertOnSubmit(blockItem);
            DataContext.SubmitChanges();

            return(blockItem.iTemplateBlockItemID);
        }
        /// <summary>
        /// 编辑数据
        /// </summary>
        /// <returns></returns>
        public int EditOneBlockItem(TemplateBlcokItem blockItem)
        {
            var blcokItemNow = GetOneBlockItem(blockItem.iTemplateBlockItemID);

            if (blcokItemNow != null)
            {
                blcokItemNow.sRemark     = blockItem.sRemark;
                blcokItemNow.sContent    = blockItem.sContent;
                blcokItemNow.iAction     = blockItem.iAction;
                blcokItemNow.iOrder      = blockItem.iOrder;
                blcokItemNow.dAddTime    = blcokItemNow.dAddTime;
                blcokItemNow.dupdateTime = blockItem.dupdateTime;

                //DataContext.SubmitChanges();

                try
                {
                    DataContext.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                }
                catch (System.Data.Linq.ChangeConflictException ex)
                {
                    foreach (System.Data.Linq.ObjectChangeConflict occ in DataContext.ChangeConflicts)
                    {
                        //以下是解决冲突的三种方法,选一种即可
                        // 使用当前数据库中的值,覆盖Linq缓存中实体对象的值
                        //occ.Resolve(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
                        // 使用Linq缓存中实体对象的值,覆盖当前数据库中的值
                        occ.Resolve(System.Data.Linq.RefreshMode.KeepCurrentValues);
                        // 只更新实体对象中改变的字段的值,其他的保留不变
                        //occ.Resolve(System.Data.Linq.RefreshMode.KeepChanges);
                    }
                    // 这个地方要注意,Catch方法中,我们前面只是指明了怎样来解决冲突,这个地方还需要再次提交更新,这样的话,值    //才会提交到数据库。
                    DataContext.SubmitChanges();
                }

                return(blockItem.iTemplateBlockItemID);
            }
            return(0);
        }
        /// <summary>
        /// 转换成对应的数据模型
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="listTemplateBlockItem"></param>
        /// <returns></returns>
        public static IBlockItem <T> ToBlockItem <T>(this TemplateBlcokItem item) where T : IBlockItemViewModel
        {
            var entity = new IBlockItem <T>();

            entity.Action      = item.iAction;
            entity.AddTime     = item.dAddTime;
            entity.BlockID     = item.iTemplateBlcokID;
            entity.BlockItemID = item.iTemplateBlockItemID;
            entity.Content     = item.sContent;
            entity.Remark      = item.sRemark;
            entity.TemplateID  = item.iTemplateID;
            entity.UpdateTime  = item.dupdateTime;
            //反序列化对应的对象
            entity.ViewModel = JsonConvert.DeserializeObject <T>(entity.Content, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore,
                NullValueHandling     = NullValueHandling.Ignore,
                DefaultValueHandling  = DefaultValueHandling.Ignore,
            });

            return(entity);
        }
        /// <summary>
        /// 数据复制
        /// </summary>
        /// <param name="iTemplateBlockItemID"></param>
        /// <returns></returns>
        public int CloneOneBlockItem(int iTemplateBlockItemID)
        {
            var blcokItemNow = GetOneBlockItem(iTemplateBlockItemID);

            if (blcokItemNow != null)
            {
                var blockItem = new TemplateBlcokItem();
                blockItem.dAddTime         = DateTime.Now;
                blockItem.dupdateTime      = DateTime.Now;
                blockItem.iAction          = 0;
                blockItem.iOrder           = 1;
                blockItem.iTemplateBlcokID = blcokItemNow.iTemplateBlcokID;
                blockItem.iTemplateID      = blcokItemNow.iTemplateID;
                //
                blockItem.sContent = blcokItemNow.sContent;
                blockItem.sRemark  = string.Format("数据复制,来源编号:{0}", blcokItemNow.iTemplateBlockItemID);
                //
                DataContext.TemplateBlcokItems.InsertOnSubmit(blockItem);
                DataContext.SubmitChanges();

                return(blockItem.iTemplateBlockItemID);
            }
            return(0);
        }
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public int AddOneBlockItem(TemplateBlcokItem blockItem)
 {
     DataContext.TemplateBlcokItems.InsertOnSubmit(blockItem);
     DataContext.SubmitChanges();
     return(blockItem.iTemplateBlockItemID);
 }
Esempio n. 7
0
 partial void DeleteTemplateBlcokItem(TemplateBlcokItem instance);
Esempio n. 8
0
 partial void UpdateTemplateBlcokItem(TemplateBlcokItem instance);
Esempio n. 9
0
 partial void InsertTemplateBlcokItem(TemplateBlcokItem instance);