asp.net core web api for POS system

Discussion in 'Programming & Software Development' started by howlingstar, Aug 20, 2018.

  1. howlingstar

    howlingstar Member

    Joined:
    Jun 9, 2015
    Messages:
    3
    Location:
    Melbourne
    Currently I'm building the API for a custom POS system to connect and be able to list products and add to cart,checkout etc. Its all working fine for now on our development environment.

    Its currently built using .net core web API with EF 2 for the database (MSSQL). I've also including JWT for security for the POS terminals to be authorized.
    I use the async/await for most methods like addToCart, removeFromCart, CommitOrder etc

    public async Task<IActionResult> AddTicketProductToCart([FromBody]AddTicketProductToCartDTO dto)
    {
    var query = from p in _context.transactioncart
    where p.TransactionCartId == dto.TransactionCartId
    select p;

    var transactioncart = await query.FirstOrDefaultAsync();
    }

    Would this approve work fine when multiple POS terminals are connected to the API and doing calls at the same time? Would it cause any duplicates or dependencies in the database context?

    I've been reading on UnitOfWork and Repository patterns that might resolve this sort of complications. Is this recommended?
    https://www.c-sharpcorner.com/article/repository-and-unitofwork-pattern-part-1/
     
    Last edited: Aug 20, 2018
  2. waltermitty

    waltermitty Member

    Joined:
    Feb 19, 2016
    Messages:
    745
    Location:
    BRISBANE
    Wrap the whole query in a transaction, use addorupdate, hell, wrap the whole request pipeline in a transaction if you like. If the TransactionCartIds match, it'll be last in wins for concurrent connections.
     

Share This Page