Exemplo n.º 1
0
        public ErrorCode AddPerm(PrevilegeVM perm)
        {
            var previlegeDal = new PrevilegeDAL();
            try
            {
                if (
                    previlegeDal.GetExisted(
                        o => o.ActionId == perm.ActionId && o.ControllerId == perm.ControllerId && o.RoleId == perm.RoleId))
                {
                    return ErrorCode.NoError;
                }

                var previlege = new Previlege
                                    {
                                        RoleId = perm.RoleId,
                                        PrevilegeLevel = (int) perm.PrevilegeLevel,
                                        ControllerId = perm.ControllerId,
                                        ActionId = perm.ActionId
                                    };
                previlegeDal.Create(previlege);
                return ErrorCode.NoError;
            }
            catch (Exception)
            {
                return ErrorCode.ServerError;
            }
        }
Exemplo n.º 2
0
        public ErrorCode RemovePerm(PrevilegeVM perm)
        {
            var previlegeDal = new PrevilegeDAL();

            try
            {
                if (perm.PrevilegeLevel == PrevilegeLevel.ActionLevel && (!previlegeDal.GetExisted(
                    o =>
                    o.ActionId == perm.ActionId && o.ControllerId == perm.ControllerId && o.RoleId == perm.RoleId &&
                    o.PrevilegeLevel == (int)PrevilegeLevel.ActionLevel)))
                {
                    return ErrorCode.NoError;
                }

                if (perm.PrevilegeLevel == PrevilegeLevel.ControllerLevel && (!previlegeDal.GetExisted(
                    o => o.ControllerId == perm.ControllerId && o.RoleId == perm.RoleId &&
                    o.PrevilegeLevel == (int)PrevilegeLevel.ControllerLevel)))
                {
                    return ErrorCode.NoError;
                }

                var previlege = new Previlege
                {
                    RoleId = perm.RoleId,
                    PrevilegeLevel = (int)perm.PrevilegeLevel,
                    ControllerId = perm.ControllerId,
                    ActionId = perm.ActionId
                };

                var existed = new List<Previlege>();
                if (previlege.PrevilegeLevel == (int)PrevilegeLevel.ControllerLevel)
                {
                    //existed = QueryForObjs(GetObjQuery<RolePrevilege>(ctx),
                    //		 o => o.RoleId == perm.RoleId && o.ControllerId == perm.ControllerId && o.PrevilegeLevel == (int)PrevilegeLevel.ControllerLevel).ToList();
                    existed =
                        previlegeDal.Query(
                            o =>
                            o.RoleId == perm.RoleId && o.ControllerId == perm.ControllerId &&
                            o.PrevilegeLevel == (int) PrevilegeLevel.ControllerLevel).ToList();
                }
                else if (previlege.PrevilegeLevel == (int)PrevilegeLevel.ActionLevel)
                {
                    //existed = QueryForObjs(GetObjQuery<RolePrevilege>(ctx),
                    //		 o => o.ActionId == perm.ActionId && o.RoleId == perm.RoleId && o.ControllerId == perm.ControllerId && o.PrevilegeLevel == (int)PrevilegeLevel.ActionLevel).ToList();
                    existed =
                        previlegeDal.Query(
                            o =>
                            o.ActionId == perm.ActionId && o.RoleId == perm.RoleId && o.ControllerId == perm.ControllerId &&
                            o.PrevilegeLevel == (int) PrevilegeLevel.ActionLevel).ToList();
                }

                foreach (var previlege1 in existed)
                {
                    previlegeDal.Delete(previlege1.Id);
                }

                return ErrorCode.NoError;
            }
            catch (Exception)
            {
                return ErrorCode.ServerError;
            }
        }