Esempio n. 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);
 }
Esempio n. 2
0
        public ActionResult AddRoles(Dictionary <string, string> input)
        {
            sys_roles r = JsonConvert.DeserializeObject <sys_roles>(input["inputData"]);

            if (!input.ContainsKey("type"))
            {
                if (!_db.Queryable <sys_roles>().Where(_r => _r.name == r.name).Any())
                {
                    r.ID = _db.Insertable(r).ExecuteReturnBigIdentity();
                }
                else
                {
                    return(new ActionResult(false, null, null, "该角色已存在"));
                }
            }
            else if (input["type"] == "del")
            {
                _db.Deleteable <sys_roles>().Where(o => o.ID == r.ID).ExecuteCommand();
                _db.Deleteable <sys_func_roles_link>().Where(frl => frl.rid == r.ID).ExecuteCommand();
            }
            return(new ActionResult(true, r));
        }
Esempio n. 3
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);
        }