Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
public static string ImportSales(CarDealerContext context, string inputJson) { ICollection
salesToImport = new List
(); IEnumerable
saleDtos = JsonConvert.DeserializeObject
(inputJson); if (saleDtos != null) { foreach (ImportSaleDto saleDto in saleDtos) { if (!IsValid(saleDto)) { continue; } bool isCarIdExisting = context .Cars .Any(c => c.Id == saleDto.CarId); if (!isCarIdExisting) { continue; } bool isCustomerIdExisting = context .Customers .Any(cu => cu.Id == saleDto.CustomerId); if (!isCustomerIdExisting) { continue; } Sale newsale = new Sale() { CarId = saleDto.CarId, CustomerId = saleDto.CustomerId, Discount = saleDto.Discount }; salesToImport.Add(newsale); } context.Sales.AddRange(salesToImport); context.SaveChanges(); } return $"Successfully imported {salesToImport.Count}."; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)