Ejemplo n.º 1
0
 public async Task <int> Add(RoleStrActions roleStrActions)
 {
     return(await WithConnection(async c =>
     {
         StringBuilder sql = new StringBuilder();
         IDbTransaction trans = c.BeginTransaction();
         try
         {
             sql.Append(" insert into Role ")
             .Append(" values (0,@role_name,@description, ")
             .Append(" @CreatedTime,@CreatedBy,@UpdatedTime,@UpdatedBy); ")
             .Append("select last_insert_id()");
             int result = await c.QueryFirstOrDefaultAsync <int>(sql.ToString(), roleStrActions, trans);
             foreach (string item in roleStrActions.actions.Split(','))
             {
                 sql.Clear();
                 sql.Append(" insert into Role_Action ")
                 .Append(" values (0," + result + "," + item + ") ");
                 await c.ExecuteAsync(sql.ToString(), trans);
             }
             trans.Commit();
             return result;
         }
         catch (Exception ex)
         {
             trans.Rollback();
             throw new Exception(ex.ToString());
         }
     }));
 }
Ejemplo n.º 2
0
 public async Task <int> Update(RoleStrActions roleStrActions)
 {
     return(await WithConnection(async c =>
     {
         StringBuilder sql = new StringBuilder();
         IDbTransaction trans = c.BeginTransaction();
         try
         {
             sql.Append(" update Role ")
             .Append(" set role_name=@role_name,description=@description, ")
             .Append(" updated_time=@UpdatedTime,updated_by=@UpdatedBy where id=@id ");
             int result = await c.ExecuteAsync(sql.ToString(), roleStrActions, trans);
             sql.Clear().Append("delete from Role_Action where role_id=@id");
             await c.ExecuteAsync(sql.ToString(), roleStrActions, trans);
             foreach (string item in roleStrActions.actions.Split(','))
             {
                 sql.Clear()
                 .Append(" insert into Role_Action ")
                 .Append(" values (0," + roleStrActions.Id + "," + item + ") ");
                 await c.ExecuteAsync(sql.ToString(), trans);
             }
             trans.Commit();
             return result;
         }
         catch (Exception ex)
         {
             trans.Rollback();
             throw new Exception(ex.ToString());
         }
     }));
 }
Ejemplo n.º 3
0
        public async Task <MSSResult> Add(RoleStrActions roleStrActions)
        {
            MSSResult mRet = new MSSResult();

            try
            {
                DateTime dt = DateTime.Now;
                roleStrActions.UpdatedTime = dt;
                roleStrActions.CreatedTime = dt;
                roleStrActions.CreatedBy   = userID;
                roleStrActions.UpdatedBy   = userID;
                bool isRepeat = await _RoleRepo.IsNameRepeat(roleStrActions.role_name);

                if (isRepeat)
                {
                    mRet.code = (int)ErrType.Repeat;
                    mRet.msg  = "角色名称重复";
                }
                else
                {
                    mRet.data = await _RoleRepo.Add(roleStrActions);
                    await SaveRedis();

                    mRet.code = (int)ErrType.OK;
                }
                return(mRet);
            }
            catch (Exception ex)
            {
                mRet.code = (int)ErrType.SystemErr;
                mRet.msg  = ex.Message;
                return(mRet);
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <ApiResult> > Update(RoleStrActions roleStrActions)
        {
            await _RoleService.Update(roleStrActions);

            ApiResult resp = new ApiResult();

            resp.code = Code.Success;
            return(resp);
        }
Ejemplo n.º 5
0
        public async Task <MSSResult> Update(RoleStrActions roleStrActions)
        {
            MSSResult mRet = new MSSResult();

            try
            {
                roleStrActions.UpdatedTime = DateTime.Now;
                roleStrActions.UpdatedBy   = userID;
                var role = await _RoleRepo.GetByID(roleStrActions.Id);

                if (role == null)
                {
                    mRet.code = (int)ErrType.NoRecord;
                    mRet.msg  = "此角色已不存在";
                }
                else
                {
                    if (role.role_name != roleStrActions.role_name)
                    {
                        bool isRepeat = await _RoleRepo.IsNameRepeat(roleStrActions.role_name);

                        if (isRepeat)
                        {
                            mRet.code = (int)ErrType.Repeat;
                            mRet.msg  = "角色名称重复";
                            return(mRet);
                        }
                    }
                    mRet.data = await _RoleRepo.Update(roleStrActions);
                    await SaveRedis();

                    mRet.code = (int)ErrType.OK;
                }
                return(mRet);
            }
            catch (Exception ex)
            {
                mRet.code = (int)ErrType.SystemErr;
                mRet.msg  = ex.Message;
                return(mRet);
            }
        }