Esempio n. 1
0
        public Result <EmptyResult> DisassociateOrganizationUserFromGroup(DisassociateOrganizationUserFromGroupCommand command)
        {
            if (command.OrganizationId <= 0)
            {
                return(new Result <EmptyResult>(GroupServiceErrors.InvalidDisassociateOrganizationUserFromGroupDataError(nameof(command.OrganizationId))));
            }

            if (command.GroupId <= 0)
            {
                return(new Result <EmptyResult>(GroupServiceErrors.InvalidDisassociateOrganizationUserFromGroupDataError(nameof(command.GroupId))));
            }

            if (!groupRepository.GroupExists(command.GroupId, command.OrganizationId))
            {
                return(new Result <EmptyResult>(GroupServiceErrors.GroupNotFoundError()));
            }

            if (!organizationUserRepository.OrganizationUserExists(command.OrganizationUserId, command.OrganizationId))
            {
                return(new Result <EmptyResult>(GroupServiceErrors.OrganizationUserNotFoundError()));
            }

            var result = groupRepository.DisassociateOrganizationUserFromGroup(command);

            if (!result)
            {
                return(new Result <EmptyResult>(GroupServiceErrors.InvalidDisassociateOrganizationUserFromGroupDataError()));
            }

            return(new Result <EmptyResult>());
        }
Esempio n. 2
0
        public bool DisassociateOrganizationUserFromGroup(DisassociateOrganizationUserFromGroupCommand command)
        {
            var entity = this
                         .GetValidGroupMembers(command.OrganizationId)
                         .FirstOrDefault(g => g.GroupId.Equals(command.GroupId) &&
                                         g.OrganizationUserId.Equals(command.OrganizationUserId));

            if (entity is null)
            {
                return(false);
            }

            entity.DeletedAt = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            context.SaveChanges();

            return(true);
        }