예제 #1
0
        /// <summary>
        /// Update Permission
        /// </summary>
        /// <param name="permission"></param>
        /// <returns></returns>
        public void Update(PermissionDomain permission)
        {
            var permissionDb = _context.Permission.FirstOrDefault(x => x.PermissionId == permission.Id);

            permissionDb.FromDomainModel(permission);
            _context.SaveChanges();
        }
예제 #2
0
 private void ValidatePermissionModel(PermissionDomain permission)
 {
     ValidationHelper.NotNull(permission, MembershipMessages.PermissionNotProvided);
     ValidationHelper.MaxLength(permission.Code, 100, MembershipMessages.PermissionCodeLenghtExceeded);
     ValidationHelper.NotNullOrWhitespace(permission.Code, MembershipMessages.PermissionCodeInvalid);
     ValidationHelper.GreaterThanZero(permission.ModuleId, MembershipMessages.ModuleIdInvalid);
     ValidationHelper.NotNull(_moduleRepository.GetById(permission.ModuleId), MembershipMessages.ModuleWithIdDoesNotExist);
 }
예제 #3
0
        /// <summary>
        /// Adds new permission  to the database
        /// </summary>
        /// <param name="permission">Permission information to be added. Instance of <see cref="PermissionDomain"/></param>
        /// <returns>PermissionId of the newly created permission</returns>
        public int Add(PermissionDomain permission)
        {
            var permissionDb = new Permission().FromDomainModel(permission);

            _context.Permission.Add(permissionDb);
            _context.SaveChanges();
            return(permissionDb.PermissionId);
        }
예제 #4
0
 /// <summary>
 /// Map from DataBase Permission
 /// </summary>
 public static PermissionForListViewModel MapFromDbObject(PermissionDomain permission)
 {
     return(new PermissionForListViewModel
     {
         PermissionId = permission.Id,
         Code = permission.Code,
         IsActive = permission.IsActive
     });
 }
예제 #5
0
        /// <summary>
        /// Adds new permission  to the database
        /// </summary>
        /// <param name="permission">Permission information to be added. Instance of <see cref="PermissionDomain"/></param>
        /// <returns>PermissionId of the newly created permission</returns>
        public int AddPermission(PermissionDomain permission)
        {
            ValidatePermissionModel(permission);
            //Check if code exists
            var permissionWithProvidedCode = _permissionRepository.GetByCode(permission.Code.SafeTrim());

            if (permissionWithProvidedCode != null)
            {
                throw new NsiArgumentException(MembershipMessages.PermissionCodeAlreadyExists, Common.Enumerations.SeverityEnum.Warning);
            }

            return(_permissionRepository.Add(permission));
        }
예제 #6
0
        public static Permission FromDomainModel(this Permission obj, PermissionDomain domain)
        {
            if (obj == null)
            {
                obj = new Permission();
            }

            obj.PermissionId = domain.Id;
            obj.IsActive     = domain.IsActive;
            obj.ModuleId     = domain.ModuleId;
            obj.Code         = domain.Code;

            return(obj);
        }
예제 #7
0
        /// <summary>
        /// Update Permission
        /// </summary>
        /// <param name="permission"></param>
        /// <returns></returns>
        public void UpdatePermission(PermissionDomain permission)
        {
            ValidatePermissionModel(permission);
            ValidationHelper.GreaterThanZero(permission.Id, MembershipMessages.PermissionIdInvalid);
            ValidationHelper.NotNull(_permissionRepository.GetById(permission.Id), MembershipMessages.PermissionWithIdDoesNotExist);

            var permissionWithProvidedCode = _permissionRepository.GetByCode(permission.Code);

            if (permissionWithProvidedCode != null && permissionWithProvidedCode.Id != permission.Id)
            {
                throw new NsiArgumentException(MembershipMessages.PermissionCodeAlreadyExists, Common.Enumerations.SeverityEnum.Warning);
            }

            _permissionRepository.Update(permission);
        }
예제 #8
0
        public IHttpActionResult AddPermission(AddPermissionRequest request)
        {
            request.ValidateNotNull();

            PermissionDomain permissionDomain = new PermissionDomain()
            {
                Code     = request.Code,
                IsActive = request.IsActive,
                ModuleId = request.ModuleId
            };

            return(Ok(new AddPermissionResponse()
            {
                Data = _permissionManipulation.AddPermission(permissionDomain),
                Success = Common.Enumerations.ResponseStatus.Succeeded
            }));
        }
예제 #9
0
        public IHttpActionResult UpdatePermission(UpdatePermissionRequest request)
        {
            request.ValidateNotNull();
            PermissionDomain permissionDomain = _permissionManipulation.GetPermissionById(request.Id);

            if (permissionDomain == null)
            {
                return(NotFound());
            }

            permissionDomain.Code     = request.Code;
            permissionDomain.IsActive = request.IsActive;
            permissionDomain.ModuleId = request.ModuleId;

            _permissionManipulation.UpdatePermission(permissionDomain);

            return(Ok(new UpdatePermissionResponse()
            {
                Success = Common.Enumerations.ResponseStatus.Succeeded
            }));
        }
예제 #10
0
        public void GetModuleById_Success()
        {
            PermissionDomain module = _permissionManipulation.GetPermissionById(1);

            Assert.AreEqual(1, module.Id);
        }
예제 #11
0
        public void GetModuleByCode_Success()
        {
            PermissionDomain module = _permissionManipulation.GetPermissionByCode("TESTCODEEXISTS");

            Assert.AreEqual("TESTCODEEXISTS", module.Code);
        }
 public CoreAccessAuthorizeAttribute(PermissionDomain domain, PermissionActionCondition condition, params PermissionAction[] actions)
 {
     this._domain    = domain;
     this._actions   = actions;
     this._condition = condition;
 }
 public CoreAccessAuthorizeAttribute(PermissionDomain domain, PermissionAction action)
 {
     this._domain    = domain;
     this._actions   = new PermissionAction[] { action };
     this._condition = PermissionActionCondition.And;
 }