public ActionResult AddProductToOrder(int? orderId, int? productId) { // find op order en product var orderItem = db.OrderDetails.SingleOrDefault(o => o.OrderId == orderId && o.ProductId == productId); Product prod = db.Products.Find(productId); // nieuwe quotation detail if (orderItem == null) { orderItem = new OrderDetail { ProductId = (int)productId, OrderId = (int)orderId, Quantity = 1, Auvibel = prod.Auvibel, Bebat = prod.Bebat, CategoryId = prod.CategoryId, Brand = prod.Brand, Description = prod.Description, PriceExVAT = prod.PriceExVAT, ProductCode = prod.ProductCode, ProductName = prod.ProductName, Recupel = prod.Recupel, Reprobel = prod.Reprobel, VATPercId = prod.VATPercId, }; orderItem.VAT = db.VATs.Find(orderItem.VATPercId); db.OrderDetails.Add(orderItem); } else { orderItem.Quantity++; } orderItem.TotalExVat = (orderItem.PriceExVAT + orderItem.Auvibel + orderItem.Bebat + orderItem.Recupel + orderItem.Reprobel) * orderItem.Quantity; //Berekent totaal per lijn van producten inc BTW orderItem.TotalIncVat = orderItem.TotalExVat * (1 + (orderItem.VAT.VATValue / 100)); CalculateTotalPriceinc(orderId); db.SaveChanges(); return RedirectToAction("AddProducts", new { id = orderId }); }
public ActionResult CreateOrder(int? Id) { Order order = new Order(); Quotation quot = new Quotation(); quot = db.Quotations.Find(Id); order.Annotation = quot.Annotation + " - Order van Offerte " + quot.QuotationNumber; order.Box = quot.Box; order.CellPhone = quot.CellPhone; order.CustomerId = quot.CustomerId; order.Date = quot.Date; order.Email = quot.Email; order.FirstName = quot.FirstName; order.LastName = quot.LastName; order.PostalCodeNumber = quot.PostalCodeNumber; order.StreetName = quot.StreetName; order.StreetNumber = quot.StreetNumber; order.TotalPrice = quot.TotalPrice; order.Town = quot.Town; order.Active = true; quot.Active = false; db.Orders.Add(order); db.SaveChanges(); order.customerDeliveryAddress = quot.customerDeliveryAddress; //find highest order number int maxOrderNumber = 1; order.OrderNumber = maxOrderNumber; var listOrders = db.Orders.ToList(); if (listOrders.Count > 1) { maxOrderNumber = listOrders.Max(o => o.OrderNumber); order.OrderNumber = maxOrderNumber + 1; } foreach (var item in quot.QuotationDetail) { var od = new OrderDetail(); od.OrderId = order.OrderId; od.Quantity = item.Quantity; od.PriceExVAT = item.PriceExVAT; od.TotalExVat = item.TotalExVat; od.TotalIncVat = item.TotalIncVat; od.Auvibel = item.Auvibel; od.Bebat = item.Bebat; od.Brand = item.Brand; od.CategoryId = item.CategoryId; od.Description = item.Description; od.ProductCode = item.ProductCode; od.ProductName = item.ProductName; od.Recupel = item.Recupel; od.Reprobel = item.Reprobel; od.VATPercId = item.VATPercId; od.ProductId = item.ProductId; od.VAT = item.VAT; db.OrderDetails.Add(od); } db.SaveChanges(); return RedirectToAction("Index", "Orders"); }