public async Task <ActionResult> Create([Bind(Include = "Id,ProductTypeId,Price,Name,CustomerId")] AddOn addOn) { if (ModelState.IsValid) { var customerId = await _customerIdService.GetCustomerId(); addOn.CustomerId = customerId; await _addOnRepository.Add(addOn); return(RedirectToAction("Index")); } var productTypes = await GetProductTypes(); ViewBag.ProductTypeId = new SelectList(productTypes, "Id", "Description", addOn.ProductTypeId); return(View(addOn)); }
public OrderDto MakeOrder(IEnumerable <int> products) { _logger.LogDebug("Call MakeOrder method"); var orderedProducts = _productRepository.GetAll().Where(prod => products.Contains(prod.Id)).ToArray(); var ordersProducts = orderedProducts.Select(product => new OrderProduct { ProductId = product.Id }).ToList(); var newOrder = new Order { OrderProducts = ordersProducts }; _ordersRepository.Add(newOrder); return(new OrderDto(_ordersRepository.GetAll().LastOrDefault())); }