/// <summary>
 /// 获取单条数据
 /// </summary>
 /// <returns></returns>
 public V_xy_sp_spiritskill Get(Expression <Func <xy_sp_spiritskill, bool> > predicate = null)
 {
     using (xy_sp_spiritskillDAL dal = new xy_sp_spiritskillDAL()){
         xy_sp_spiritskill entity = dal.Get(predicate);
         return(EntityToModel(entity));
     }
 }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Edit(V_xy_sp_spiritskill model)
        {
            if (model == null)
            {
                return(false);
            }
            using (xy_sp_spiritskillDAL dal = new xy_sp_spiritskillDAL()){
                xy_sp_spiritskill entitys = ModelToEntity(model);

                return(dal.Edit(entitys));
            }
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string Add(V_xy_sp_spiritskill model)
        {
            if (model == null)
            {
                return(string.Empty);
            }

            using (xy_sp_spiritskillDAL dal = new xy_sp_spiritskillDAL()){
                xy_sp_spiritskill entity = ModelToEntity(model);
                entity.SpiritSkillID = string.IsNullOrEmpty(model.SpiritSkillID) ? Guid.NewGuid().ToString("N") : model.SpiritSkillID;

                return(dal.Add(entity));
            }
        }
        /// <summary>
        /// Model转Entity
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private xy_sp_spiritskill ModelToEntity(V_xy_sp_spiritskill model)
        {
            if (model != null)
            {
                xy_sp_spiritskill entity = new xy_sp_spiritskill()
                {
                    SpiritSkillID = model.SpiritSkillID,
                    SpiritID      = model.SpiritID,
                    SkillID       = model.SkillID,
                    IsReady       = model.IsReady,
                };

                return(entity);
            }
            return(null);
        }
        /// <summary>
        /// Entity转Model
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        private V_xy_sp_spiritskill  EntityToModel(xy_sp_spiritskill entity)
        {
            if (entity != null)
            {
                xy_sp_skillBLL      bll   = new xy_sp_skillBLL();
                V_xy_sp_spiritskill model = new V_xy_sp_spiritskill()
                {
                    SpiritSkillID = entity.SpiritSkillID,
                    SpiritID      = entity.SpiritID,
                    SkillID       = entity.SkillID,
                    IsReady       = entity.IsReady,
                    skill         = bll.Get(c => c.SkillID == entity.SkillID)
                };

                return(model);
            }

            return(null);
        }