/// <inheritdoc/>
        public async Task JoinSpace(string spaceId)
        {
            if (await this._authorizationService.IsAuthorizedAsync(
                    "join_spaces"))
            {
                if (this._authorizationService.User != null)
                {
                    var userSpaces = this._configDatabaseContext.UserSpaces
                                     .Where(us => us.UserId ==
                                            this._authorizationService.User.Subject.ToLower())
                                     .ToList().FirstOrDefault();

                    if (Guid.TryParse(spaceId, out Guid spaceGuid))
                    {
                        if (userSpaces != null)
                        {
                            if (!userSpaces.SpaceIds !
                                .Contains(spaceId.ToLower()))
                            {
                                userSpaces.SpaceIds !.Append(
                                    spaceId.ToLower());
                            }

                            this._configDatabaseContext.UserSpaces
                            .Update <UserSpaces, string>(userSpaces);
                        }
                        else
                        {
                            userSpaces = new Database.Config.Models.UserSpaces
                            {
                                UserId = this._authorizationService.User
                                         .Subject.ToLower(),
                                SpaceIds = new List <string>
                                {
                                    spaceId.ToLower(),
                                },
                            };

                            this._configDatabaseContext.UserSpaces
                            .Add <UserSpaces, string>(userSpaces);
                        }
                    }
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserSpacesResponse"/>
 /// class.
 /// </summary>
 /// <param name="userSpaces">The source userspaces.</param>
 public UserSpacesResponse(Database.Config.Models.UserSpaces userSpaces)
 {
     this.UserId   = userSpaces.UserId;
     this.SpaceIds = userSpaces.SpaceIds;
 }