Пример #1
0
        /// <summary>
        /// Creates a roleplay with the given parameters.
        /// </summary>
        /// <param name="owner">The user that owns the roleplay.</param>
        /// <param name="server">The server that the roleplay is associated with.</param>
        /// <param name="roleplayName">The name of the roleplay.</param>
        /// <param name="roleplaySummary">The summary of the roleplay.</param>
        /// <param name="isNSFW">Whether or not the roleplay is NSFW.</param>
        /// <param name="isPublic">Whether or not the roleplay is public.</param>
        /// <returns>A creation result which may or may not have been successful.</returns>
        public async Task <CreateEntityResult <Roleplay> > CreateRoleplayAsync
        (
            User owner,
            Server server,
            string roleplayName,
            string roleplaySummary,
            bool isNSFW,
            bool isPublic
        )
        {
            owner  = _database.NormalizeReference(owner);
            server = _database.NormalizeReference(server);

            // Use a dummy name, since we'll be setting it using the service.
            var roleplay = _database.CreateProxy <Roleplay>(server, owner, string.Empty, string.Empty);

            _database.Attach(roleplay);

            var ownerParticipant = _database.CreateProxy <RoleplayParticipant>(roleplay, owner);

            ownerParticipant.Status = ParticipantStatus.Joined;

            roleplay.ParticipatingUsers.Add(ownerParticipant);

            var setNameResult = await SetRoleplayNameAsync(roleplay, roleplayName);

            if (!setNameResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(setNameResult));
            }

            var setSummaryResult = await SetRoleplaySummaryAsync(roleplay, roleplaySummary);

            if (!setSummaryResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(setSummaryResult));
            }

            roleplay.IsNSFW   = isNSFW;
            roleplay.IsPublic = isPublic;

            _database.Roleplays.Update(roleplay);

            await _database.SaveChangesAsync();

            return(roleplay);
        }
Пример #2
0
        public async Task <CreateEntityResult <Roleplay> > CreateRoleplayAsync
        (
            [NotNull] ICommandContext context,
            [NotNull] string roleplayName,
            [NotNull] string roleplaySummary,
            bool isNSFW,
            bool isPublic
        )
        {
            var getOwnerResult = await _users.GetOrRegisterUserAsync(context.User);

            if (!getOwnerResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(getOwnerResult));
            }

            // Ensure the user is attached, so we don't create any conflicts.
            var owner = getOwnerResult.Entity;

            _database.Attach(owner);

            // Use a dummy name, since we'll be setting it useng the service.
            var roleplay = new Roleplay((long)context.Guild.Id, owner, string.Empty);

            var ownerParticipant = new RoleplayParticipant(roleplay, owner)
            {
                Status = ParticipantStatus.Joined
            };

            roleplay.ParticipatingUsers.Add(ownerParticipant);

            var setNameResult = await SetRoleplayNameAsync(context, roleplay, roleplayName);

            if (!setNameResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(setNameResult));
            }

            var setSummaryResult = await SetRoleplaySummaryAsync(roleplay, roleplaySummary);

            if (!setSummaryResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(setSummaryResult));
            }

            var setIsNSFWResult = await SetRoleplayIsNSFWAsync(roleplay, isNSFW);

            if (!setIsNSFWResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(setIsNSFWResult));
            }

            var setIsPublicResult = await SetRoleplayIsPublicAsync(roleplay, isPublic);

            if (!setIsPublicResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(setIsPublicResult));
            }

            _database.Roleplays.Update(roleplay);

            await _database.SaveChangesAsync();

            var roleplayResult = await GetUserRoleplayByNameAsync(context, context.Message.Author, roleplayName);

            if (!roleplayResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(roleplayResult));
            }

            return(CreateEntityResult <Roleplay> .FromSuccess(roleplayResult.Entity));
        }