add amount * price linq commands detail

  • Thread starter Thread starter djnilo
  • Start date Start date
D

djnilo

Guest
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);
}

1445705.jpg

Continue reading...
 
Back
Top