public async Task <IActionResult> Create([Bind("CustomerEmail,OrderDate,FullProductCount,TotalPrice,CustomerOrderId,ProductName")] BalloonParty.DataAccess.SQLData.CustomerOrders customerOrders) { var prodPrices = _context.Products.ToList(); if (ModelState.IsValid) { var cso = new BalloonParty.Core.Models.CustomerOrders { CustomerEmail = customerOrders.CustomerEmail, OrderDate = DateTime.Now, FullProductCount = customerOrders.FullProductCount, TotalPrice = customerOrders.FullProductCount * prodPrices.SingleOrDefault(p => p.ProductName == customerOrders.ProductName).ProductPrice, CustomerOrderId = customerOrders.CustomerOrderId, ProductName = customerOrders.ProductName, }; customerOrders = BalloonParty.DataAccess.Mapper.MapCustomerOrderCORE(cso); _context.Add(customerOrders); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CustomerEmail"] = new SelectList(_context.Customer, "EmailAddress", "EmailAddress", customerOrders.CustomerEmail); ViewData["ProductName"] = new SelectList(_context.Products, "ProductName", "ProductName", customerOrders.ProductName); return(View(customerOrders)); }
public static BalloonParty.DataAccess.SQLData.CustomerOrders MapCustomerOrderCORE(BalloonParty.Core.Models.CustomerOrders customerOrders) { return(new BalloonParty.DataAccess.SQLData.CustomerOrders { CustomerEmail = customerOrders.CustomerEmail, OrderDate = customerOrders.OrderDate, FullProductCount = customerOrders.FullProductCount, TotalPrice = customerOrders.TotalPrice, CustomerOrderId = customerOrders.CustomerOrderId, ProductName = customerOrders.ProductName, }); }