-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d133d32
commit 607b292
Showing
39 changed files
with
2,200 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+455 KB
ExamPrep-05-January-2018/01. Model Definition_Problem Description.docx
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27130.2010 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PetClinic", "PetClinic\PetClinic.csproj", "{71D8C54E-627D-44BF-B6EC-E193775F3AD3}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{71D8C54E-627D-44BF-B6EC-E193775F3AD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{71D8C54E-627D-44BF-B6EC-E193775F3AD3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{71D8C54E-627D-44BF-B6EC-E193775F3AD3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{71D8C54E-627D-44BF-B6EC-E193775F3AD3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {69692160-5FF9-478A-9CC8-7B608EB7323D} | ||
EndGlobalSection | ||
EndGlobal |
27 changes: 27 additions & 0 deletions
27
ExamPrep-05-January-2018/PetClinic/App/PetClinicProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace PetClinic.App | ||
{ | ||
using AutoMapper; | ||
using PetClinic.Models; | ||
|
||
public class PetClinicProfile : Profile | ||
{ | ||
public PetClinicProfile() | ||
{ | ||
/* | ||
* | ||
Някои тестове гърмят с Automappera в Judge!!! | ||
* | ||
*/ | ||
|
||
//CreateMap<Dto.ImportDtos.AnimalAidsDto, AnimalAid>(); | ||
|
||
//CreateMap<Dto.ImportDtos.AnimalDto, Animal>(); | ||
|
||
//CreateMap<Dto.ImportDtos.PassportDto, Passport>(); | ||
|
||
//CreateMap<Dto.ImportDtos.VetDto, Vet>(); | ||
|
||
// CreateMap<Dto.ImportDtos.ProcedureDto, Procedure>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
namespace PetClinic.App | ||
{ | ||
using System; | ||
using System.IO; | ||
|
||
using AutoMapper; | ||
|
||
using PetClinic.Data; | ||
|
||
public class StartUp | ||
{ | ||
static void Main() | ||
{ | ||
using (var context = new PetClinicContext()) | ||
{ | ||
Mapper.Initialize(config => config.AddProfile<PetClinicProfile>()); | ||
|
||
ResetDatabase(context); | ||
|
||
ImportEntities(context); | ||
|
||
ExportEntities(context); | ||
|
||
BonusTask(context); | ||
} | ||
} | ||
|
||
private static void ImportEntities(PetClinicContext context, string baseDir = @"..\..\..\Datasets\") | ||
{ | ||
const string exportDir = @"..\..\..\Results\"; | ||
|
||
string animalAids = DataProcessor.Deserializer.ImportAnimalAids(context, File.ReadAllText(baseDir + "animalAids.json")); | ||
PrintAndExportEntityToFile(animalAids, exportDir + "AnimalAidsImport.txt"); | ||
|
||
string animals = DataProcessor.Deserializer.ImportAnimals(context, File.ReadAllText(baseDir + "animals.json")); | ||
PrintAndExportEntityToFile(animals, exportDir + "AnimalsImport.txt"); | ||
|
||
string vets = DataProcessor.Deserializer.ImportVets(context, File.ReadAllText(baseDir + "vets.xml")); | ||
PrintAndExportEntityToFile(vets, exportDir + "VetsImport.txt"); | ||
|
||
var procedures = DataProcessor.Deserializer.ImportProcedures(context, File.ReadAllText(baseDir + "procedures.xml")); | ||
PrintAndExportEntityToFile(procedures, exportDir + "ProceduresImport.txt"); | ||
} | ||
|
||
private static void ExportEntities(PetClinicContext context) | ||
{ | ||
const string exportDir = @"..\..\..\Results\"; | ||
|
||
string animalsExport = DataProcessor.Serializer.ExportAnimalsByOwnerPhoneNumber(context, "0887446123"); | ||
PrintAndExportEntityToFile(animalsExport, exportDir + "AnimalsExport.json"); | ||
|
||
string proceduresExport = DataProcessor.Serializer.ExportAllProcedures(context); | ||
PrintAndExportEntityToFile(proceduresExport, exportDir + "ProceduresExport.xml"); | ||
} | ||
|
||
private static void BonusTask(PetClinicContext context) | ||
{ | ||
var bonusOutput = DataProcessor.Bonus.UpdateVetProfession(context, "+359284566778", "Primary Care"); | ||
Console.WriteLine(bonusOutput); | ||
} | ||
|
||
private static void PrintAndExportEntityToFile(string entityOutput, string outputPath) | ||
{ | ||
Console.WriteLine(entityOutput); | ||
File.WriteAllText(outputPath, entityOutput.TrimEnd()); | ||
} | ||
|
||
private static void ResetDatabase(PetClinicContext context) | ||
{ | ||
context.Database.EnsureDeleted(); | ||
context.Database.EnsureCreated(); | ||
|
||
Console.WriteLine("Database reset."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace PetClinic.Data | ||
{ | ||
public static class Configuration | ||
{ | ||
public static string ConnectionString = @"Server=.;Database=PetClinic;Trusted_Connection=True"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
ExamPrep-05-January-2018/PetClinic/Data/EntityConfigurations/AnimalAidConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace PetClinic.Data.EntityConfigurations | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using PetClinic.Models; | ||
|
||
public class AnimalAidConfig : IEntityTypeConfiguration<AnimalAid> | ||
{ | ||
public void Configure(EntityTypeBuilder<AnimalAid> builder) | ||
{ | ||
builder.HasAlternateKey(ai => ai.Name); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
ExamPrep-05-January-2018/PetClinic/Data/EntityConfigurations/AnimalConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace PetClinic.Data.EntityConfigurations | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using PetClinic.Models; | ||
|
||
public class AnimalConfig : IEntityTypeConfiguration<Animal> | ||
{ | ||
public void Configure(EntityTypeBuilder<Animal> builder) | ||
{ | ||
builder.HasOne(a => a.Passport) | ||
.WithOne(p => p.Animal) | ||
.HasForeignKey<Animal>(a => a.PassportSerialNumber); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
ExamPrep-05-January-2018/PetClinic/Data/EntityConfigurations/ProcedureAnimalAidConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace PetClinic.Data.EntityConfigurations | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using PetClinic.Models; | ||
|
||
public class ProcedureAnimalAidConfig : IEntityTypeConfiguration<ProcedureAnimalAid> | ||
{ | ||
public void Configure(EntityTypeBuilder<ProcedureAnimalAid> builder) | ||
{ | ||
builder.HasKey(x => new { x.AnimalAidId, x.ProcedureId }); | ||
|
||
builder.HasOne(x => x.AnimalAid) | ||
.WithMany(ai => ai.AnimalAidProcedures) | ||
.HasForeignKey(x => x.AnimalAidId); | ||
|
||
builder.HasOne(x => x.Procedure) | ||
.WithMany(p => p.ProcedureAnimalAids) | ||
.HasForeignKey(x => x.ProcedureId); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
ExamPrep-05-January-2018/PetClinic/Data/EntityConfigurations/ProcedureConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace PetClinic.Data.EntityConfigurations | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using PetClinic.Models; | ||
|
||
public class ProcedureConfig : IEntityTypeConfiguration<Procedure> | ||
{ | ||
public void Configure(EntityTypeBuilder<Procedure> builder) | ||
{ | ||
builder.HasOne(p => p.Animal) | ||
.WithMany(a => a.Procedures) | ||
.HasForeignKey(p => p.AnimalId); | ||
|
||
builder.HasOne(p => p.Vet) | ||
.WithMany(v => v.Procedures) | ||
.HasForeignKey(p => p.VetId); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
ExamPrep-05-January-2018/PetClinic/Data/EntityConfigurations/VetConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace PetClinic.Data.EntityConfigurations | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using PetClinic.Models; | ||
|
||
public class VetConfig : IEntityTypeConfiguration<Vet> | ||
{ | ||
public void Configure(EntityTypeBuilder<Vet> builder) | ||
{ | ||
builder.HasAlternateKey(v => v.PhoneNumber); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
ExamPrep-05-January-2018/PetClinic/Data/PetClinicContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace PetClinic.Data | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using PetClinic.Data.EntityConfigurations; | ||
using PetClinic.Models; | ||
|
||
public class PetClinicContext : DbContext | ||
{ | ||
public PetClinicContext() { } | ||
|
||
public PetClinicContext(DbContextOptions options) | ||
:base(options) { } | ||
|
||
public DbSet<Animal> Animals { get; set; } | ||
public DbSet<Passport> Passports { get; set; } | ||
public DbSet<Procedure> Procedures { get; set; } | ||
public DbSet<ProcedureAnimalAid> ProceduresAnimalAids { get; set; } | ||
public DbSet<AnimalAid> AnimalAids { get; set; } | ||
public DbSet<Vet> Vets { get; set; } | ||
|
||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
if (!optionsBuilder.IsConfigured) | ||
{ | ||
optionsBuilder.UseSqlServer(Configuration.ConnectionString); | ||
} | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder builder) | ||
{ | ||
builder.ApplyConfiguration(new AnimalAidConfig()); | ||
builder.ApplyConfiguration(new AnimalConfig()); | ||
builder.ApplyConfiguration(new ProcedureAnimalAidConfig()); | ||
builder.ApplyConfiguration(new ProcedureConfig()); | ||
builder.ApplyConfiguration(new VetConfig()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace PetClinic.DataProcessor | ||
{ | ||
using System.Linq; | ||
using PetClinic.Data; | ||
|
||
public class Bonus | ||
{ | ||
public static string UpdateVetProfession(PetClinicContext context, string phoneNumber, string newProfession) | ||
{ | ||
var vet = context.Vets.Where(x => x.PhoneNumber == phoneNumber).FirstOrDefault(); | ||
|
||
if (vet == null) | ||
{ | ||
return $"Vet with phone number {phoneNumber} not found!"; | ||
} | ||
|
||
var oldProfession = vet.Profession; | ||
vet.Profession = newProfession; | ||
|
||
context.SaveChanges(); | ||
|
||
return $"{vet.Name}'s profession updated from {oldProfession} to {newProfession}."; | ||
} | ||
} | ||
} |
Oops, something went wrong.