//------------------------------------------------------------------------------------------
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="entity"></param>
 public bool Append(Role_action entity)
 {
     try
     {
        bool result = _Role_actionDal.Append(entity);
        ClearCacheData();
        return result;
     }
     catch (Exception ex)
     {
         DealError(ex);
         return false;
     }
 }
        //------------------------------------------------------------------------------------------
        /// <summary>
        /// 增加一条记录
        /// </summary>
        /// <param name="entity"></param>
        public bool Append(Role_action entity)
        {
            string sqlCmd = "insert into mp_role_action (ResourceID ,ControllerName ,ActionName ,DisplayName ,Sort ,Status ,CreateTime ,IsShowInMenu ,LastModifyTime ,Remarks) values (@ResourceID ,@ControllerName ,@ActionName ,@DisplayName ,@Sort ,@Status ,@CreateTime ,@IsShowInMenu ,@LastModifyTime ,@Remarks);SELECT  LAST_INSERT_ID();";
            MySqlParameter[] pars = new MySqlParameter[10];
            pars[0] = new MySqlParameter("@ResourceID",entity.ResourceID);
            pars[1] = new MySqlParameter("@ControllerName",entity.ControllerName);
            pars[2] = new MySqlParameter("@ActionName",entity.ActionName);
            pars[3] = new MySqlParameter("@DisplayName",entity.DisplayName);
            pars[4] = new MySqlParameter("@Sort",entity.Sort);
            pars[5] = new MySqlParameter("@Status",entity.Status);
            pars[6] = new MySqlParameter("@CreateTime",entity.CreateTime);
            pars[7] = new MySqlParameter("@IsShowInMenu",entity.IsShowInMenu);
            pars[8] = new MySqlParameter("@LastModifyTime",entity.LastModifyTime);
            pars[9] = new MySqlParameter("@Remarks",entity.Remarks);

            entity.ActionID = Convert.ToInt32(MySqlHelper.ExecuteScalar(CommandType.Text, sqlCmd,pars));
            return true;
        }
        //------------------------------------------------------------------------------------------
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity"></param>
        public bool Update(Role_action entity)
        {
            string sqlCmd = "update mp_role_action set  ResourceID = @ResourceID, ControllerName = @ControllerName, ActionName = @ActionName, DisplayName = @DisplayName, Sort = @Sort, Status = @Status, CreateTime = @CreateTime, IsShowInMenu = @IsShowInMenu, LastModifyTime = @LastModifyTime, Remarks = @Remarks  where   ActionID =  @ActionID ";

            MySqlParameter[] pars = new MySqlParameter[11];
            pars[0] = new MySqlParameter("@ActionID",entity.ActionID);
            pars[1] = new MySqlParameter("@ResourceID",entity.ResourceID);
            pars[2] = new MySqlParameter("@ControllerName",entity.ControllerName);
            pars[3] = new MySqlParameter("@ActionName",entity.ActionName);
            pars[4] = new MySqlParameter("@DisplayName",entity.DisplayName);
            pars[5] = new MySqlParameter("@Sort",entity.Sort);
            pars[6] = new MySqlParameter("@Status",entity.Status);
            pars[7] = new MySqlParameter("@CreateTime",entity.CreateTime);
            pars[8] = new MySqlParameter("@IsShowInMenu",entity.IsShowInMenu);
            pars[9] = new MySqlParameter("@LastModifyTime",System.DateTime.Now);
            pars[10] = new MySqlParameter("@Remarks",entity.Remarks);

            return MySqlHelper.ExecuteNonQuery(CommandType.Text,sqlCmd,  pars);
        }
 //------------------------------------------------------------------------------------------
 /// <summary>
 /// 把reader转换成Entity
 /// </summary>
 /// <param name="table">表数据</param>
 /// <returns></returns>
 private Role_action DataReaderToEntity(IDataReader reader)
 {
     Role_action entity= new Role_action();
     entity.ActionID = Convert.ToInt32(reader["ActionID"]) ;
     entity.ResourceID = Convert.ToInt32(reader["ResourceID"]) ;
     entity.ControllerName = Convert.ToString(reader["ControllerName"]) ;
     entity.ActionName = Convert.ToString(reader["ActionName"]) ;
     entity.DisplayName = Convert.ToString(reader["DisplayName"]) ;
     entity.Sort = Convert.ToInt32(reader["Sort"]) ;
     entity.Status = Convert.ToSByte(reader["Status"]) ;
     entity.CreateTime = Convert.ToDateTime(reader["CreateTime"]) ;
     entity.IsShowInMenu = Convert.ToSByte(reader["IsShowInMenu"]) ;
     entity.LastModifyTime = Convert.ToDateTime(reader["LastModifyTime"]) ;
     entity.Remarks = Convert.ToString(reader["Remarks"]) ;
     return entity;
 }
Beispiel #5
0
        public ActionResult SaveAction(int? ActionID)
        {
            string backUrl = Url.Action("actions");
            Role_action entity = new Role_action();
            string[] allowProperty = new string[] { "ControllerName", "ActionName", "ResourceID", "DisplayName", "Sort", "Status", "IsShowInMenu" };

            PageCommandType type = PageCommandType.增加;
            if (ActionID.HasValue)
            {
                //目前只考虑主键只有一个,且为自增长
                entity = Role_actionBLL.Current.GetByID(ActionID.Value);
                if (entity != null)
                {
                    type = PageCommandType.更新;
                }
            }
            TryUpdateModel(entity, allowProperty);

            entity.LastModifyTime = DateTime.Now;
            entity.ControllerName = (entity.ControllerName ?? string.Empty).Trim();
            entity.ActionName = (entity.ActionName ?? string.Empty).Trim();
            //增加操作
            if (type == PageCommandType.增加)
            {

                if (Role_actionBLL.Current.Append(entity))
                {
                    return CommonResult.ShowMessage("增加成功", string.Format("/role/editaction/{0}", entity.ActionID));
                }
            }
            else if (type == PageCommandType.更新)
            {

                if (Role_actionBLL.Current.Update(entity))
                {
                    return CommonResult.ShowMessage("更新成功", string.Format("/role/editaction/{0}", entity.ActionID));
                }
            }
            return CommonResult.ShowMessage("保存失败", backUrl);
        }