Exemple #1
0
        /// <summary>
        /// Sets the contents of the given note.
        /// </summary>
        /// <param name="note">The note.</param>
        /// <param name="content">The content.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetNoteContentsAsync(UserNote note, string content)
        {
            if (content.IsNullOrWhitespace())
            {
                return(ModifyEntityResult.FromError("You must provide some content for the note."));
            }

            if (content.Length > 1024)
            {
                return(ModifyEntityResult.FromError
                       (
                           "The note is too long. It can be at most 1024 characters."
                       ));
            }

            if (note.Content == content)
            {
                return(ModifyEntityResult.FromError("That's already the note's contents."));
            }

            note.Content = content;
            note.NotifyUpdate();

            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
    /// <summary>
    /// Sets the contents of the given note.
    /// </summary>
    /// <param name="note">The note.</param>
    /// <param name="content">The content.</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> SetNoteContentsAsync
    (
        UserNote note,
        string content,
        CancellationToken ct = default
    )
    {
        content = content.Trim();

        if (content.IsNullOrWhitespace())
        {
            return(new UserError("You must provide some content for the note."));
        }

        if (content.Length > 1024)
        {
            return(new UserError
                   (
                       "The note is too long. It can be at most 1024 characters."
                   ));
        }

        if (note.Content == content)
        {
            return(new UserError("That's already the note's contents."));
        }

        note.Content = content;
        note.NotifyUpdate();

        await _database.SaveChangesAsync(ct);

        return(Result.FromSuccess());
    }