Example #1
0
        /// <summary>
        /// Adds a condition to the given autorole.
        /// </summary>
        /// <param name="autorole">The autorole.</param>
        /// <param name="condition">The condition.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> AddConditionAsync
        (
            AutoroleConfiguration autorole,
            AutoroleCondition condition
        )
        {
            if (autorole.Conditions.Any(c => c.HasSameConditionsAs(condition)))
            {
                return(ModifyEntityResult.FromError
                       (
                           "There's already a condition with the same settings in the autorole."
                       ));
            }

            autorole.Conditions.Add(condition);
            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Example #2
0
    /// <summary>
    /// Adds a condition to the given autorole.
    /// </summary>
    /// <param name="autorole">The autorole.</param>
    /// <param name="condition">The condition.</param>
    /// <param name="ct">The cancellation token in use.</param>
    /// <returns>A modification result which may or may not have succeeded.</returns>
    public async Task <Result> AddConditionAsync
    (
        AutoroleConfiguration autorole,
        AutoroleCondition condition,
        CancellationToken ct = default
    )
    {
        if (autorole.Conditions.Any(c => c.HasSameConditionsAs(condition)))
        {
            return(new UserError
                   (
                       "There's already a condition with the same settings in the autorole."
                   ));
        }

        autorole.Conditions.Add(condition);
        await _database.SaveChangesAsync(ct);

        return(Result.FromSuccess());
    }