//[HasPermission(typeof(CanUpdateCustomerUserRequirement))] TODO User management Permissions
        public Task <ActionResult <User> > removeFromCustomer([FromRoute] int id, [FromBody] int customerId)
        {
            var request = new RemoveFromCustomerRequest()
            {
                UserId = id, CustomerId = customerId
            };

            return(this._userService.RemoveFromCustomer(request).Convert <User>(this));
        }
Exemplo n.º 2
0
        public async Task <IWrappedResponse> RemoveFromCustomer(RemoveFromCustomerRequest request)
        {
            var user = _userRepo.FindAll().IgnoreQueryFilters().Include(u => u.Customers)
                       .SingleOrDefault(u => !u.IsDeleted && u.Id == request.UserId);
            var relation = _userCustomerRelationRepo.FindAll().IgnoreQueryFilters().FirstOrDefault(c => c.UserId == request.UserId && c.CustomerId == request.CustomerId);

            if (user != null && relation != null)
            {
                _userCustomerRelationRepo.Delete(relation);
                _userCustomerRelationRepo.Save();

                // Eventuelle ungültiger Permission Cache
                await _permissionsService.UpdateCache();
            }
            return(Ok(_mapper.Map <User>(user)));
        }