public async Task <bool> CreateCakeOrder(CakeOrderViewModel model, CancellationToken ct = default(CancellationToken)) { Customer cus = _customerRepository.GetByIdentityId(model.IdentityId); var initialData = await this.GetInitialData(); //calculate total price again List <string> toppings = model.Toppings.Split(',').ToList(); ICake cake = initialData.CakeShapes.Where(x => x.Code.Trim() == model.ShapeCode.Trim()).FirstOrDefault(); cake.Toppings = initialData.Toppings.Where(w => toppings.Any(code => code.Trim() == w.Code.Trim())).ToList(); cake.Message = model.Message; cake.Size = model.Size; model.TotalPrice = cake.CalculatePrice(); CakeOrder order = new CakeOrder(); order.CustomerId = cus.Id; order.Message = model.Message; order.ShapeCode = model.ShapeCode; order.Size = model.Size; order.TotalPrice = model.TotalPrice; order = await _cakeOrderRepository.AddAsync(order); foreach (var topping in cake.Toppings) { Topping toppingEntity = new Topping(); toppingEntity.CakeOrderId = order.Id; toppingEntity.Code = topping.Code; await _toppingRepository.AddAsync(toppingEntity); } return(true); }