Blazor Server + Web API HTTP POST or PUT - write all or write none

wavemaster 311 Reputation points
2021-04-06T20:26:06.303+00:00

I am working on modernization of a transactional app written in the 2012 Microsoft flavor of the year. The old app uses EF 6.4.

The modernized app is based on Blazor Server and Web API.

Currently I am at the point where I need to save a newly created Transaction into the db, and I am looking for an example that will show this technique, however I need to have some sort of do or die implementation where everthing is written or nothing is written.

In addition to the Transaction and its 5 related Entities there are several other Entities that I need to save. Cannot find anything but Author / Book or TodoList examples.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BApiEf5.Model.Custom
{
    public class RecordDetail
    {
        public int TransactionId { get; set; }
        public string CName { get; set; }
        public string LName { get; set; }

        public DateTime TDate { get; set; }
        public string BDate { get; set; }
        public string Initials { get; set; }
        public bool IsBilled { get; set; }
        public bool IsPaid { get; set; }
        public string SvcLevel { get; set; }

        public bool IsAdjusted { get; set; }
        public decimal adjAddOn { get; set; }
        public decimal Tax { get; set; }
        public decimal ccAddOn { get; set; }
        public decimal Charge { get; set; }
        public decimal PayAmount { get; set; }

        public string CurrencySymbol { get; set; }

        public List<ServiceItem> ServiceItems { get; set; }
        public List<ShoeItem> ShoeItems { get; set; }
        public List<FileItem> FileItems { get; set; }
        public List<ImageItem> ImageItems { get; set; }
        public List<NoteItem> NoteItems { get; set; }
        public List<VoiceItem> VoiceItems { get; set; }
    }
}

My application is Blazor + WebAPI so EF Core 5.0.X

What you provided in the link is how I do things in the old app. Now I have EF Core and WebAPI.

Whether this happens in the Blazor page,or in the Controller (please advise where), I will have to make HTTP PUT requests for all involved Entities, something like 8.

Would like to see the technique that ensures, that all 8 are written, or all 8 fail. Please send me a link or something to a tutorial

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,479 questions
{count} votes

1 answer

Sort by: Most helpful
  1. wavemaster 311 Reputation points
    2021-04-07T02:58:47.9+00:00

    Oh, I see MS wants me to use Edge, so it happily refuses my post without further explanation. Epic time waster again.

    I am sorry I am not going to retype it.