Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevin 35 posts 159 karma points
    Nov 22, 2016 @ 20:01
    Kevin
    0

    Add additional notes to existing invoice

    Hi what is the correct way to do this.

    I create my note and save it:

    var noteService = MerchelloContext.Current.Services.NoteService;
    var note = noteService.CreateNote(invoice.Key, EntityType.Invoice, "My note text");
    note.Author = "System Note";
    note.CreateDate = DateTime.UtcNow;
    note.InternalOnly = false;
    noteService.Save(note);
    

    But then I need to update the invoice notes collection - or do I - this part just feels weird.

    // TODO: must be a better way
    var allNotes = new List<INote>();  // new notes list
    if (invoice.Notes != null)
        allNotes.AddRange(invoice.Notes); // add existing notes to new list
    allNotes.Add(note);  // add new note to list
    invoice.Notes = allNotes;  // pass new list to invoice
    MerchelloContext.Current.Services.InvoiceService.Save(invoice);  // save invoice
    

    Thanks

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 23, 2016 @ 17:08
    Rusty Swayne
    0

    Hey Kevin - yes that part is a bit weird and is a result of the notes going through a couple rounds of refactoring .

    I think we need to provide some extension methods for both Invoice and Customer to make things more fluid.

    One thing though ... you should not need to save the note with the note service:

     var noteService = MerchelloContext.Current.Services.NoteService;
     var note = noteService.CreateNote(invoice.Key, EntityType.Invoice, "My note text");
     note.Author = "System Note";
     note.CreateDate = DateTime.UtcNow;
     note.InternalOnly = false;
     noteService.Save(note); // <- should not need this line
    
Please Sign in or register to post replies

Write your reply to:

Draft