public void MakeOrderDetails(Orderdetails orderDetailsDto) { DataLayer.Orderdetails orderDetails = new DataLayer.Orderdetails { Orderid = orderDetailsDto.Orderid, Positionid = orderDetailsDto.Positionid, Quantity = orderDetailsDto.Quantity }; Database.Orderdetails.Create(orderDetails); Database.Save(); }
public ActionResult MakeOrder(string name, int quantity) { IEnumerable <BusinessLogic.Menu> menu = restaurantService.GetMenu(); var mapper1 = new MapperConfiguration(cfg => cfg.CreateMap <BusinessLogic.Menu, MenuViewModel>()).CreateMapper(); var menus = mapper1.Map <IEnumerable <BusinessLogic.Menu>, List <MenuViewModel> >(menu); IEnumerable <BusinessLogic.Orders> order = restaurantService.GetOrder(); var mapper2 = new MapperConfiguration(cfg => cfg.CreateMap <BusinessLogic.Orders, OrderViewModel>()).CreateMapper(); var orders = mapper2.Map <IEnumerable <BusinessLogic.Orders>, List <OrderViewModel> >(order); var last = orders.LastOrDefault().Orderid; int price = 0; var IDs = AreCheckedDish.ToArray(); var quantities = Points.ToArray(); for (int i = 0; i < IDs.Length; i++) { var detailsDto = new BusinessLogic.Orderdetails { Orderid = last + 1, Quantity = quantities[i], Positionid = IDs[i] }; restaurantService.MakeOrderDetails(detailsDto); foreach (var item in menus) { if (IDs[i] == item.Positionid) { price += quantities[i] * (item.Price ?? 0); } } } var orderDto = new BusinessLogic.Orders { Clientname = name, Price = price }; restaurantService.MakeOrder(orderDto); return(new RedirectToPageResult("/")); }