Esempio n. 1
0
 /// <summary>
 /// 保存实体数据(新增、修改)
 /// <param name="keyValue">主键</param>
 /// <summary>
 /// <returns></returns>
 public void SaveEntity(string keyValue, dm_decoration_template_moduleEntity entity)
 {
     try
     {
         if (!string.IsNullOrWhiteSpace(keyValue))
         {
             entity.Modify(keyValue);
             this.BaseRepository("dm_data").Update(entity);
         }
         else
         {
             entity.Create();
             this.BaseRepository("dm_data").Insert(entity);
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowServiceException(ex);
         }
     }
 }
        /// <summary>
        /// 保存装修模板数据
        /// </summary>
        /// <param name="jsondata"></param>
        public void SaveDecorationTemplateData(int templateid, string jsondata)
        {
            IRepository db = null;

            try
            {
                List <ModuleItem> moduleItemList = jsondata.ToObject <List <ModuleItem> >();
                List <dm_decoration_template_moduleEntity>      dm_decoration_template_moduleList      = new List <dm_decoration_template_moduleEntity>();
                List <dm_decoration_template_module_itemEntity> dm_decoration_template_module_itemList = new List <dm_decoration_template_module_itemEntity>();
                foreach (ModuleItem item in moduleItemList)
                {
                    dm_decoration_template_moduleEntity dm_Decoration_Template_ModuleEntity = new dm_decoration_template_moduleEntity();
                    dm_Decoration_Template_ModuleEntity.template_id = item.template_id;
                    dm_Decoration_Template_ModuleEntity.module_id   = item.module_id;
                    dm_Decoration_Template_ModuleEntity.Create();
                    dm_decoration_template_moduleList.Add(dm_Decoration_Template_ModuleEntity);

                    foreach (dm_decoration_template_module_itemEntity entity in item.module_item_list)
                    {
                        entity.template_module_id = dm_Decoration_Template_ModuleEntity.id;
                        entity.template_id        = templateid;
                        entity.Create();
                        dm_decoration_template_module_itemList.Add(entity);
                    }
                }
                if (templateid > 0)
                {
                    db = this.BaseRepository("dm_data").BeginTrans();
                    db.Delete <dm_decoration_template_moduleEntity>(t => t.template_id == templateid);
                    db.Delete <dm_decoration_template_module_itemEntity>(t => t.template_id == templateid);
                    if (dm_decoration_template_moduleList.Count > 0)
                    {
                        db.Insert(dm_decoration_template_moduleList);
                        db.Insert(dm_decoration_template_module_itemList);
                    }
                    db.Commit();
                }
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }

                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
 /// <summary>
 /// 保存实体数据(新增、修改)
 /// <param name="keyValue">主键</param>
 /// <summary>
 /// <returns></returns>
 public void SaveEntity(string keyValue, dm_decoration_template_moduleEntity entity)
 {
     try
     {
         dm_decoration_template_moduleService.SaveEntity(keyValue, entity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }