none
add amount * price linq commands detail RRS feed

  • Question

  • hello good afternoon programmers and I occupy visual studio 2015 I am developing an application in c # entity framework sql 2014 I have a form orders it turns out that I need to return a product comanda_detalle - comanda
    Command

    SELECT [IdComanda]
           ,[Date]
           ,[Total amount]
           , [IdMesa]

       FROM [dbo]. [Commands]
    comanda_detalle

    SELECT [IdDetalle]
           , [IdComanda]
           , [Product Id]
           , [ProductName]
           ,[Price]
           ,[Quantity]
    from Comanda_Detalle

    example: place an order with 2 products each product is worth $ 500
    the total = $ 1000
    so now I need to return a $ 500 product
    the total would be $ 500
    the updated value I need to put it in the demand. Total Amount = $ 500

    what I intend is to make you calculate price * amount so that you give me the amount = amountTotal
    that total amount I need to update the command.monototal = total amount

       coma = repository.FindEntity <Comanda> (x => x.IdComanda == comanda.IdComanda, "Comanda_Detalles");
                  
                    decimal totalComanda = 0;
                    if (comma! = null)
                    {
                        foreach (var item in comanda.Comanda_Detalles)
                        {
                            totalComanda = (item.Price * item.Quantity);
                          
    
                        }
                        coma.MontoTotal = totalComanda;
                     
                    }
    

    public bool DevolverItem (Comanda comanda, Comanda_Detalle detalle)
            {
                DAL.IUnitOfWork repository = new Model.RepositoryUoW ();
                bool Result = false;
                try
                {

                    
              

                    var comandas = repository.FindEntity <PRODUCT> (x => x.IdProduct == detail.IdProduct);
                    if (command! = null)
                    {
                        if (comandas.CalcularStock)
                        {
                            comandas.Stock = comandas.Stock + detalle.Cantidad;
                            repository.Update <PRODUCT> (commands);
                        }

                       
                        var return = new Return ();
                      
                      
                        return.Quantity = detail.Quantity;
                        return.Date = command.Date;
                        return.IdComanda = detail.IdComanda;
                  
                        return.IdPriority = Convert.ToInt32 (detail.IdPriority);
                        return.IdProduct = detail.IdProduct;
                   
                        return.ProductName = detail.ProductName;
                       
                        return.Price = detail.Price;

                        repository.Create <Return> (return);
                    }

                    coma = repository.FindEntity <Comanda> (x => x.IdComanda == comanda.IdComanda, "Comanda_Detalles");
                  
                    decimal totalComanda = 0;
                    if (comma! = null)
                    {
                        foreach (var item in comanda.Comanda_Detalles)
                        {
                            totalComanda = (item.Price * item.Quantity);
                          

                        }
                        coma.MontoTotal = totalComanda;
                     
                    }

                 
                   

                    repository.Update <Command> (comma);
                  
                    repository.Delete <Comanda_Detalle> (detail);
                    repository.Save ();
                    Result = true;
                    return Result;
                   

                }
                catch (Exception ex)
                {

                    throw new Exception (ex.Message);
                }

    Monday, June 3, 2019 12:04 AM

All replies

  • Hi djnilo,

    Thank you for posting here.

    Since this thread is related to entity framework, I will move it to ADO.NET Entity Framework and LINQ to Entities forum to get support.

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 3, 2019 5:04 AM
  • I am not a fan of the generic repository pattern. The repository pattern is not a data persistence pattern. 

    However, what does the EF persistence model look like? 

    Show the code for the model the repositroy object is working with.


    • Edited by DA924x Monday, June 3, 2019 7:30 AM
    Monday, June 3, 2019 7:30 AM