public async Task <Guid> Handle(UpdatemMenuResource request, CancellationToken cancellationToken)
        {
            var findEntity = await _context.MenuResources.FindAsync(request.Model).ConfigureAwait(false);

            _ = _mapper.Map(request.Model, findEntity);
            await _context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            return(findEntity.Id);
        }
Example #2
0
        public async Task <Guid> Handle(AddPageResource request, CancellationToken cancellationToken)
        {
            var entity = _mapper.Map <PageResource>(request.Model);

            _context.PageResources.Add(entity);
            await _context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            return(entity.Id);
        }
        public async Task <bool> Handle(AssignRoleToResourceDto request, CancellationToken cancellationToken)
        {
            var checkIfExist = await _dbContext.AccessControls.OfType <RoleAccessControl>()
                               .SingleOrDefaultAsync(x => x.ResourceId == request.ResourceId && x.RoleName == request.RoleName);

            RoleAccessControl entity = checkIfExist == null?_mapper.Map <RoleAccessControl>(request) : _mapper.Map(request, checkIfExist);

            _dbContext.Entry(entity).State = checkIfExist is null ? EntityState.Added : EntityState.Modified;
            var effected = await _dbContext.SaveChangesAsync(cancellationToken);

            return(effected > 0);
        }