Esempio n. 1
0
        public void Execute(RoleDto request)
        {
            _validator.ValidateAndThrow(request); //ValidationException
            var exisitingPermissions = _context.RolePermissions.Where(o => o.RoleId == request.Id).ToList();

            foreach (var item in exisitingPermissions)
            {
                _context.Entry(item).State = EntityState.Deleted;
            }
            var role = new Roles()
            {
                Id       = request.Id,
                RoleName = request.RoleName
            };

            foreach (var item in request.PerimissionIds)
            {
                var rolePermission = new RolePermissions()
                {
                    PermissionId = item,
                    RoleId       = request.Id
                };
                _context.Entry(rolePermission).State = EntityState.Added;
            }
            _context.Entry(role).State = EntityState.Modified;

            _context.SaveChanges();
        }
        public void Execute(RoleDto request)
        {
            _validator.ValidateAndThrow(request);

            var role = _context.Roles.Find(request.Id);

            role.RoleName = request.RoleName;

            _context.SaveChanges();
        }
Esempio n. 3
0
        public void Execute(RolePutDto request)
        {
            _validator.ValidateAndThrow(request);

            var role = _context.Roles.Find(request.Id);

            if (role == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(Role));
            }

            role.Name = request.Name;
            _context.SaveChanges();
        }
Esempio n. 4
0
        public void Execute(RoleDto request)
        {
            if (_context.Categories.Find(request.Id) == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(Reply));
            }

            _validator.ValidateAndThrow(request);

            var role = _context.Roles.Find(request.Id);

            _mapper.Map(request, role);
            _context.SaveChanges();
        }