public async Task <IActionResult> CalculateCost([FromBody] CartOptionsSerializer data)
        {
            decimal ItemPrice      = 0;
            string  ShoppingCartId = db.GetUserName(HttpContext);
            Cart    item           = await db.Cart.Include(t => t.Template).ThenInclude(p => p.Product).FirstOrDefaultAsync(c => c.CartId == ShoppingCartId && c.RecordId == data.ItemId);

            if (item.Template.Product.CategoryId != 9)
            {
                Paper paper = await db.Paper.FirstOrDefaultAsync(x => x.PrintType == data.PrintType && x.PaperType == data.PaperType && x.PaperDensity == data.PaperDensity);

                PrintPrice printPrice = await db.PrintPrice.FirstOrDefaultAsync(x => x.PrintType == data.PrintType && x.Sides == item.Template.Product.Type && x.Quantity == data.Quantity);

                if (printPrice != null)
                {
                    ItemPrice  = data.Quantity * (paper.Price + printPrice.Price);
                    item.Paper = paper;
                }
                else
                {
                    return(Json("error"));
                }
            }
            else
            {
                ItemPrice = data.Quantity * item.Template.Product.Price;
            }
            item.Quantity = data.Quantity;
            item.Price    = ItemPrice;
            db.Cart.Update(item);
            await db.SaveChangesAsync();

            decimal Total = GetTotal();

            return(Json(new { Id = item.RecordId, ItemPrice = ItemPrice.ToString(), Total = Total.ToString() }));
        }
Ejemplo n.º 2
0
 private int calculatePrintPrice(PrintPrice priceModel)
 {
     return(priceModel.Price);
 }