예제 #1
0
 public (Boolean success, string msg) Add(Role role)
 {
     if (!Exist(role.Name))
     {
         var _role = new sys_roles();
         _role.Mapp(role);
         _baseQueryRepository.Context.Insertable(_role).ExecuteReturnIdentity();
     }
     else
     {
         role.ID = -1;
         return(false, $"角色【{role.Name}】已经存在");
     }
     return(true, null);
 }
예제 #2
0
        public bool SaveChange(Role entity)
        {
            var snapshot = GetById(entity.ID);
            var rlt      = _baseQueryRepository.Context.Ado.UseTran(() =>
            {
                var role = new sys_roles();
                role.Mapp(entity);
                _baseQueryRepository.Context.Updateable(role).Where(r => r.ID == entity.ID)
                .ExecuteCommand();
                snapshot.Funcs.Where(f => !entity.Funcs.Exists(ff => ff.Fid == f.Fid)).ToList().ForEach(f =>
                {
                    _baseQueryRepository.Context.Ado.ExecuteCommand("delete from sys_func_roles_link where fid=@fid and rid=@rid;"
                                                                    , new { rid = entity.ID, fid = f.Fid });
                });
                entity.Funcs.Where(f => !snapshot.Funcs.Exists(ff => ff.Fid == f.Fid)).ToList().ForEach(f =>
                {
                    var frl = new sys_func_roles_link();
                    frl.Mapp(f);
                    _baseQueryRepository.Context.Insertable(frl).ExecuteCommand();
                });
            });

            return(rlt.IsSuccess);
        }