Artillery - svetlilaloli/EntityFramework-SoftUni GitHub Wiki
Your task is to create a database application, using Entity Framework Core, using the Code First approach. Design the domain models and methods for manipulating the data, as described below.
You are given a project skeleton, which includes the following folders:
- Data β contains the ArtilleryContext class, Models folder which contains the entity classes, and the Configuration class with the connection string
- DataProcessor β contains the Deserializer and Serializer classes, which are used for importing and exporting data
- Datasets β contains the .json and .xml files for the import part
- ImportResults β contains the import results you make in the Deserializer class
- ExportResults β contains the export results you make in the Serializer class
Note: Foreign key navigation properties are required!
The application needs to store the following data:
- Id β integer, Primary Key
- CountryName β text with length [4, 60] (required)
- ArmySize β integer in the range [50_000β¦.10_000_000] (required)
- CountriesGuns β a collection of CountryGun
- Id β integer, Primary Key
- ManufacturerName β unique text with length [4β¦40] (required)
- Founded β text with length [10β¦100] (required)
- Guns β a collection of Gun
- Id β integer, Primary Key
- ShellWeight β double in the range [2β¦1_680] (required)
- Caliber β text with length [4β¦30] (required)
- Guns β a collection of Gun
- Id β integer, Primary Key
- ManufacturerId β integer, foreign key (required)
- GunWeightβ integer in range [100β¦1_350_000] (required)
- BarrelLength β double in the range [2.00β¦.35.00] (required)
- NumberBuild β integer
- Range β integer in the range [1β¦.100_000] (required)
- GunType β enumeration of GunType, with possible values (Howitzer, Mortar, FieldGun, AntiAircraftGun, MountainGun, AntiTankGun) (required)
- ShellId β integer, foreign key (required)
- CountriesGuns β a collection of CountryGun
- CountryId β Primary Key integer, foreign key (required)
- GunId β Primary Key integer, foreign key (required)
For the functionality of the application, you need to create several methods that manipulate the database. The project skeleton already provides you with these methods, inside the Deserializer class. Usage of Data Transfer Objects is optional but highly recommended.
Use the provided JSON and XML files to populate the database with data. Import all the information from those files into the database.
You are not allowed to modify the provided JSON and XML files.
If a record does not meet the requirements from the first section, print an error message:
Error message |
---|
Invalid data. |
Using the file countries.xml, import the data from that file into the database. Print information about each imported object in the format described below.
If any validation errors occur such as invalid country name or army size, do not import any part of the entity and append an error message "Invalid data." to the method output.
Success message |
---|
Successfully import {countryName} with {armySize} army personnel. |
countries.xml
<?xml version='1.0' encoding='UTF-8'?>
<Countries>
<Country>
<CountryName>Afghanistan</CountryName>
<ArmySize>1697064</ArmySize>
</Country>
<Country>
<CountryName>Afghan</CountryName>
<ArmySize>16</ArmySize>
</Country>
<Country>
<CountryName>Albania</CountryName>
<ArmySize>6296389</ArmySize>
</Country>
<Country>
<CountryName></CountryName>
<ArmySize>2401223</ArmySize>
</Country>
<Country>
<CountryName>Algeria</CountryName>
<ArmySize>1284683</ArmySize>
</Country>
β¦
</Countries>
Output |
---|
Successfully import Afghanistan with 1697064 army personnel. |
Invalid data. |
Successfully import Albania with 6296389 army personnel. |
Invalid data. |
Successfully import Algeria with 1284683 army personnel. |
... |
If your import logic is correct, you should have imported 88 countries.
Using the file manufacturers.xml, import the data from that file into the database. Print information about each imported object in the format described below.
If any validation errors occur such as invalid manufacturer name or founded, do not import any part of the entity and append an error message "Invalid data." to the method output.
The Founded entity will be separated by comma and space "**, **".
Success message |
---|
Successfully import manufacturer {manufacturerName} founded in {townName, countryName}. |
manufacturers.xml
<?xml version='1.0' encoding='UTF-8'?>
<Manufacturers>
<Manufacturer>
<ManufacturerName>BAE Systems</ManufacturerName>
<Founded>30 November 1999, London, England</Founded>
</Manufacturer>
<Manufacturer>
<ManufacturerName>BAE</ManufacturerName>
<Founded>30 November 1999, London, England</Founded>
</Manufacturer>
<Manufacturer>
<ManufacturerName>Aviation Industry Corporation of China</ManufacturerName>
<Founded>April 1, 1951, Chaoyang District, Beijing, China</Founded>
</Manufacturer>
<Manufacturer>
<ManufacturerName>General Dynamics</ManufacturerName>
<Founded>February 7, 1899, Reston, Virginia, United States</Founded>
</Manufacturer>
<Manufacturer>
<ManufacturerName>General Dynamics</ManufacturerName>
<Founded>February 7, 1899, Reston, Virginia, United States</Founded>
</Manufacturer>
<Manufacturer>
<ManufacturerName>Raytheon Technologies</ManufacturerName>
<Founded>2020, Waltham, Massachusetts, United States</Founded>
</Manufacturer>
<Manufacturer>
<ManufacturerName>Northrop Grumman</ManufacturerName>
<Founded>1994, 2980 Fairview Park Drive, West Falls Church, Virginia, United States</Founded>
</Manufacturer>
<Manufacturer>
<ManufacturerName>Lockheed Martin</ManufacturerName>
<Founded>March 15, 1995, Bethesda, Maryland, United States</Founded>
</Manufacturer>
β¦
</Manufacturers>
Output |
---|
Successfully import manufacturer BAE Systems founded in London, England. |
Invalid data. |
Successfully import manufacturer Aviation Industry Corporation of China founded in Beijing, China. |
Successfully import manufacturer General Dynamics founded in Virginia, United States. |
Invalid data. |
Successfully import manufacturer Raytheon Technologies founded in Massachusetts, United States. |
Successfully import manufacturer Northrop Grumman founded in Virginia, United States. |
Successfully import manufacturer Lockheed Martin founded in Maryland, United States. |
... |
If your import logic is correct, you should have imported 20 unique manufacturers.
Using the file shells.xml, import the data from that file into the database. Print information about each imported object in the format described below.
If any validation errors occur such as invalid: shell weight or caliber, do not import any part of the entity and append an error message "Invalid data." to the method output.
Success message |
---|
Successfully import shell caliber #{caliber} weight {shellWeigh} kg. |
shells.xml
<?xml version='1.0' encoding='UTF-8'?>
<Shells>
<Shell>
<ShellWeight>50</ShellWeight>
<Caliber>155 mm (6.1 in)</Caliber>
</Shell>
<Shell>
<ShellWeight>100</ShellWeight>
<Caliber>103 mm (8 in)</Caliber>
</Shell>
<Shell>
<ShellWeight>146</ShellWeight>
<Caliber>203 mm (8 in)</Caliber>
</Shell>
<Shell>
<ShellWeight>0</ShellWeight>
<Caliber>280 mm</Caliber>
</Shell>
<Shell>
<ShellWeight>300</ShellWeight>
<Caliber>280 mm (11 in)</Caliber>
</Shell>
<Shell>
<ShellWeight>460</ShellWeight>
<Caliber/>
</Shell>
<Shell>
<ShellWeight>1500</ShellWeight>
<Caliber>460 mm (18 in)</Caliber>
</Shell>
<Shell>
<ShellWeight>53</ShellWeight>
<Caliber>155mm</Caliber>
</Shell>
β¦
</Shells>
Output |
---|
Successfully import shell caliber #155 mm (6.1 in) weight 50 kg. |
Successfully import shell caliber #103 mm (8 in) weight 100 kg. |
Successfully import shell caliber #203 mm (8 in) weight 146 kg. |
Invalid data. |
Successfully import shell caliber #280 mm (11 in) weight 300 kg. |
Invalid data. |
Successfully import shell caliber #460 mm (18 in) weight 1500 kg. |
Successfully import shell caliber #155mm weight 53 kg. |
... |
If your import logic is correct, you should have imported 60 shells.
Using the file guns.json, import the data from the file into the database. Print information about each imported object in the format described below.
- If there are any validation errors (such as invalid gun weight, barrel length, range, gun-type), do not import any part of the entity and append an error message to the method output.
- The Countries array will always contain valid ids.
Success message |
---|
Successfully import gun {gunType} with a total weight of {gunWeight} kg. and barrel length of {barrelLength} m. |
guns.json
[
{
"ManufacturerId": 14,
"GunWeight": 531616,
"BarrelLength": 6.86,
"NumberBuild": 287,
"Range": 120000,
"GunType": "Howitzer",
"ShellId": 41,
"Countries": [
{ "Id": 86 },
{ "Id": 57 },
{ "Id": 64 },
{ "Id": 74 },
{ "Id": 58 }
]
},
{
"ManufacturerId": 8,
"GunWeight": 801684,
"BarrelLength": 31.18,
"NumberBuild": 620,
"Range": 19118,
"GunType": "AntiTankGun",
"ShellId": 38,
"Countries": [
{ "Id": 47 },
{ "Id": 3 },
{ "Id": 85 },
{ "Id": 35 },
{ "Id": 49 },
{ "Id": 53 },
{ "Id": 30 },
{ "Id": 39 },
{ "Id": 62 },
{ "Id": 6 },
{ "Id": 76 },
{ "Id": 78 },
{ "Id": 43 },
{ "Id": 72 },
{ "Id": 23 },
{ "Id": 9 },
{ "Id": 1 },
{ "Id": 21 },
{ "Id": 8 },
{ "Id": 67 },
{ "Id": 2 },
{ "Id": 33 },
{ "Id": 28 },
{ "Id": 17 },
{ "Id": 54 },
{ "Id": 4 }
]
}
...
]
Output |
---|
Invalid data. |
Successfully import gun AntiTankGun with a total weight of 801684 kg. and barrel length of 31.18 m. |
... |
If your import logic is correct, you should have imported 138 guns and 785 countries' guns.
Use the provided methods in the Serializer class. Usage of Data Transfer Objects is optional.
The given method in the projectβs skeleton receives a double representing the shell's weight. Export all shells which weight more than the given and the guns, which use this shell. For each Shell, export its ShellWeight, Caliber, and Guns. Export only the guns which are AntiAircraftGun gun type. For every gun export GunType, GunWeight, BarrelLength, and Range. If the range is greater than 3000, export "Long-range", otherwise export "Regular range". Order the guns by GunWeight (descending). Order the shells by ShellWeight (ascending).
Serializer. ExportShells(context, shellWeight)
[
{
"ShellWeight": 124.0,
"Caliber": "155 mm HE ERFB RA-BB",
"Guns": [
{
"GunType": "AntiAircraftGun",
"GunWeight": 250138,
"BarrelLength": 6.55,
"Range": "Long-range"
}
]
},
{
"ShellWeight": 146.0,
"Caliber": "203 mm (8 in)",
"Guns": []
},
...
]
Use the method provided in the project skeleton, which receives a manufacturer. Export all guns with a manufacturer equal to the given. For each gun export Manufacturer, GunType, BarrelLength, GunWeight, Range, and Countries that use this gun. Select only the Countries which has ArmySize greater than 4500000. For each country export CountryName and ArmySize. Order the countries by ArmySize (ascending). Order guns by BarrelLength (ascending).
Serializer.ExportGuns(context, manufacturer)
<?xml version="1.0" encoding="utf-16"?>
<Guns>
<Gun Manufacturer="Krupp" GunType="Mortar" GunWeight="1291272" BarrelLength="8.31" Range="14258">
<Countries>
<Country Country="Sweden" ArmySize="5437337" />
<Country Country="Portugal" ArmySize="9523599" />
</Countries>
</Gun>
<Gun Manufacturer="Krupp" GunType="AntiAircraftGun" GunWeight="1280923" BarrelLength="10.89" Range="16530">
<Countries>
<Country Country="Albania" ArmySize="6296389" />
<Country Country="United Kingdom" ArmySize="7242451" />
<Country Country="China" ArmySize="9944746" />
</Countries>
</Gun>
<Gun Manufacturer="Krupp" GunType="Howitzer" GunWeight="656499" BarrelLength="13.04" Range="80235">
<Countries>
<Country Country="Malta" ArmySize="8507869" />
</Countries>
</Gun>
<Gun Manufacturer="Krupp" GunType="FieldGun" GunWeight="431716" BarrelLength="15.7" Range="28309">
<Countries>
<Country Country="Cape Verde" ArmySize="7704194" />
<Country Country="Equatorial Guinea" ArmySize="9751317" />
</Countries>
</Gun>
<Gun Manufacturer="Krupp" GunType="Mortar" GunWeight="388420" BarrelLength="15.87" Range="6288">
<Countries>
<Country Country="Norway" ArmySize="6282380" />
<Country Country="Myanmar" ArmySize="9883310" />
</Countries>
...
</Guns>