Example #1
0
        /// <summary>
        /// Gets the caller's specified character by name, sets it as active, and updates it.
        /// </summary>
        /// <param name="callerId">Discord ID of the caller.</param>
        /// <param name="charName">The name of the character to set as active.</param>
        /// <returns>A new CharacterResult object.</returns>
        public async Task <IResult> ActivateCharacterAsync(ulong callerId, string charName)
        {
            var characters = await _provider.GetAllCharactersAsync(callerId);

            var match = characters.OrderBy(x => x.Id).FirstOrDefault(x => x.Name.ContainsIgnoreCase(charName));

            if (match == null)
            {
                return(CharacterResult.CharacterNotFound());
            }
            if (match.Active)
            {
                return(CharacterResult.CharacterAlreadyActive());
            }
            match.Active = true;

            await _provider.UpdateCharacterAsync(match);

            return(CharacterResult.CharacterActive(match.Name));
        }