public PurchaseForPurchaseController CreatePurchase(Guid customerId, [FromBody] ReceiptModel receiptModel) { Shop shop = shopRepository.CreateShop( Convert.ToInt64(receiptModel.UserInn), receiptModel.User, receiptModel.RetailPlaceAddress); Customer customer = customerRepository.GetCustomer(customerId); Purchase purchase = purchaseRepository.CreatePurchase( customer.Id, shop.Id, Convert.ToDateTime(receiptModel.DateTime), receiptModel.TotalSum ); foreach (var item in receiptModel.Items) { Product product = productRepository.CreateProduct(item.Name); ProductItem productItem = productItemRepository.CreateProductItem( product.Id, purchase.Id, item.Price / 100, item.Quantity, item.Sum / 100); } PurchaseForPurchaseController purchaseInfo = Mapper.Map <Purchase, PurchaseForPurchaseController>(purchaseRepository.GetUserPurchase(purchase.Id, customerId)); return(purchaseInfo); }