public async Task <CustomerBasketDto> OrderProductAsync(OrderSingleProductDto model) { model.CheckArgumentIsNull(); if (model.NationalCode.IsNullOrEmpty()) { throw new EntityInsufficientDataException(nameof(model.NationalCode)); } var product = await _productRepository.FindAsync(model.ProductId); ProductModel productModel = null; if (model.SelectedProductModelId.HasValue) { productModel = await _productModelRepository .FindAsync(model.SelectedProductModelId.Value); } var customer = await _customerRepository.GetByNationalCodeAsync(model.NationalCode); var shippingAddress = _shippingAddressFactory.BuildShippingAddress(model.ShippingAddress); if (customer == null) { customer = _customerFactory.BuildRealCustomerFromOrder(model); _customerValidator.ValidateCreate(customer); _customerRepository.MarkForAdd(customer); } customer.ShippingAddresses.Add(shippingAddress); var basket = await _customerFactory .AddBasketAsync(customer, product, productModel, order : model); await _customerRepository.SaveChangesAsync(); return(customer.MapToResult(basket, shippingAddress)); }