diff --git a/EHEC_Server/EHEC_Server/DataBuilder/DataSeeder.cs b/EHEC_Server/EHEC_Server/DataBuilder/DataSeeder.cs new file mode 100644 index 0000000..6e100fb --- /dev/null +++ b/EHEC_Server/EHEC_Server/DataBuilder/DataSeeder.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.ServiceModel; +using EHEC_Server.DataBuilder; +using System.Data.Entity; + + +namespace EHEC_Server.DataBuilder +{ + public class DataSeeder : EHEC_DBEntities + { + //protected override void Seed(EHEC_DBEntities context) + // { + //var doctors = GenerateDataBuilder.CreateDoctors(); + + // foreach (var d in doctors) + // { + // // context.Doctor.Add(d); + // } + // } + } +} \ No newline at end of file diff --git a/EHEC_Server/EHEC_Server/DataBuilder/GenerateDataBuilder.cs b/EHEC_Server/EHEC_Server/DataBuilder/GenerateDataBuilder.cs new file mode 100644 index 0000000..53e8891 --- /dev/null +++ b/EHEC_Server/EHEC_Server/DataBuilder/GenerateDataBuilder.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace EHEC_Server.DataBuilder +{ + public class GenerateDataBuilder + { + private static List Doctors = new List(); + private static List Patients = new List(); + private static List Origins = new List(); + private static List Results = new List(); + private static List Exams = new List(); + private static Random Rnd = new Random(); + + private static List FirstNames = new List(new string[] + { + "Michael", "Andreas", "Stefan", "Ivan","Adrien" + }); + + private static List LastNames = new List(new string[] + { + "Meister", "Schär", "Eberhard", "Zingg", "Howald", "Aebi", "Feldmann" + }); + + private static List DoctorOrigins = new List(new string[] + { + "SanktMonika", "DisneyWorld", "Hell", "Heaven" + }); + + private static List Street = new List(new string[] + { + "Rosenauweg", "Schessstrasse", "Hardstrasse", "Gehweg", "Bananastreet", "Moosweg", "Feldstrasse" + }); + + private static List BirthDate = new List(new string[] + { + "12991212", "20000112", + }); + + private static List City = new List(new string[] + { + "Meister", "Schär", "Eberhard", "Zingg", "Howald", "Aebi", "Feldmann" + }); + + + + public static List CreatePatients() + { + //int Counter = Patients.Count(); + //for (int i = 0; i < Counter; i++) + foreach (var c in FirstNames) + { + for (int j = 0; j < 10; j++) + { + Patient patient = new Patient( + FirstNames[Rnd.Next(1, FirstNames.Count())], + LastNames[Rnd.Next(1, LastNames.Count())], + BirthDate[Rnd.Next(1, BirthDate.Count())], + Street[Rnd.Next(1, Street.Count())], + City[Rnd.Next(1, City.Count())]); + Patients.Add(patient); + } + } + return Patients; + } + + public static List CreateDoctors() + { + //int Counter = Patients.Count(); + //for (int i = 0; i < Counter; i++) + foreach (var c in FirstNames) + { + for (int j = 0; j < 10; j++) + { + Doctor doctor = new Doctor( + FirstNames[Rnd.Next(1, FirstNames.Count())], + LastNames[Rnd.Next(1, LastNames.Count())], + DoctorOrigins[Rnd.Next(1, DoctorOrigins.Count())]); + Doctors.Add(doctor); + } + } + return Doctors; + } + } +} \ No newline at end of file diff --git a/EHEC_Server/EHEC_Server/DatabaseAccess/DoctorAccess.cs b/EHEC_Server/EHEC_Server/DatabaseAccess/DoctorAccess.cs new file mode 100644 index 0000000..ca663af --- /dev/null +++ b/EHEC_Server/EHEC_Server/DatabaseAccess/DoctorAccess.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.ServiceModel; + +namespace EHEC_Server.DatabaseAccess +{ + public class DoctorAccess + { + public bool CreateDoctor(Doctor doctor) + { + try + { + using (EHEC_DBEntities ctx = new EHEC_DBEntities()) + { + ctx.Doctor.Add(doctor); + ctx.SaveChanges(); + } + return true; + } + catch (Exception) + { + return false; + } + } + public List GetAllDoctors() + { + using (EHEC_DBEntities ctx = new EHEC_DBEntities()) + { + return ctx.Doctor.ToList(); + } + } + } +} \ No newline at end of file diff --git a/EHEC_Server/EHEC_Server/Doctor.cs b/EHEC_Server/EHEC_Server/Doctor.cs index b16ac2e..801119b 100644 --- a/EHEC_Server/EHEC_Server/Doctor.cs +++ b/EHEC_Server/EHEC_Server/Doctor.cs @@ -9,17 +9,41 @@ namespace EHEC_Server { + using EHEC_Server.DataBuilder; using System; using System.Collections.Generic; using System.Linq; + using EHEC_Server.DatabaseAccess; - public partial class Doctor + public partial class Doctor : DoctorAccess { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public Doctor() { this.Exam = new HashSet(); } + + + public void CreateDoctors(Doctor doctor) + { + using (EHEC_DBEntities ctx = new EHEC_DBEntities()) + { + var doctors = GenerateDataBuilder.CreateDoctors(); + + foreach (var d in doctors) + { + ctx.Doctor.Add(d); + } + } + } + + + public Doctor(string firstname, string lastname, string doctororigin) + { + this.FirstName = firstname; + this.LastName = lastname; + this.DoctorOrigin = doctororigin; + } public int DoctorId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } @@ -29,28 +53,6 @@ namespace EHEC_Server public virtual ICollection Exam { get; set; } - public bool CreateDoctor(Doctor doctor) - { - try - { - using (EHEC_DBEntities ctx = new EHEC_DBEntities()) - { - ctx.Doctor.Add(doctor); - ctx.SaveChanges(); - } - return true; - } - catch (Exception) - { - return false; - } - } - public List GetAllDoctors() - { - using (EHEC_DBEntities ctx = new EHEC_DBEntities()) - { - return ctx.Doctor.ToList(); - } - } + } } diff --git a/EHEC_Server/EHEC_Server/EHEC_Server.csproj b/EHEC_Server/EHEC_Server/EHEC_Server.csproj index d119326..bc401a1 100644 --- a/EHEC_Server/EHEC_Server/EHEC_Server.csproj +++ b/EHEC_Server/EHEC_Server/EHEC_Server.csproj @@ -106,6 +106,9 @@ + + + Model.tt @@ -145,6 +148,7 @@ + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/EHEC_Server/EHEC_Server/IService.cs b/EHEC_Server/EHEC_Server/IService.cs index 8de05a4..dee7f35 100644 --- a/EHEC_Server/EHEC_Server/IService.cs +++ b/EHEC_Server/EHEC_Server/IService.cs @@ -11,6 +11,9 @@ namespace EHEC_Server [ServiceContract] public interface IService { + [OperationContract] + void CreateRandomData(Doctor doctor); + [OperationContract] void WriteDoctor(Doctor doctor); diff --git a/EHEC_Server/EHEC_Server/Model.Designer.cs b/EHEC_Server/EHEC_Server/Model.Designer.cs index c202905..52e55a9 100644 --- a/EHEC_Server/EHEC_Server/Model.Designer.cs +++ b/EHEC_Server/EHEC_Server/Model.Designer.cs @@ -1,4 +1,4 @@ -// T4 code generation is enabled for model 'C:\Users\ism_c\source\repos\EHEC_Server\EHEC_Server\Model.edmx'. +// T4 code generation is enabled for model 'C:\Users\ism_c\source\repos\oop_II-6\EHEC_Server\EHEC_Server\Model.edmx'. // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model // is open in the designer. diff --git a/EHEC_Server/EHEC_Server/Model.edmx b/EHEC_Server/EHEC_Server/Model.edmx index 7731382..235c975 100644 --- a/EHEC_Server/EHEC_Server/Model.edmx +++ b/EHEC_Server/EHEC_Server/Model.edmx @@ -175,7 +175,7 @@ - + diff --git a/EHEC_Server/EHEC_Server/Patient.cs b/EHEC_Server/EHEC_Server/Patient.cs index 381342d..5cdbfff 100644 --- a/EHEC_Server/EHEC_Server/Patient.cs +++ b/EHEC_Server/EHEC_Server/Patient.cs @@ -21,10 +21,20 @@ namespace EHEC_Server this.Exam = new HashSet(); } + public Patient(string firstname, string lastname, string birthDate, string street, string city) + { + this.FirstName = firstname; + this.LastName = lastname; + this.BirthDate = birthDate; + this.Street = street; + this.City = city; + } + public int PatientId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } - public System.DateTime BirthDate { get; set; } + //public System.DateTime BirthDate { get; set; } + public string BirthDate { get; set; } public string Street { get; set; } public string City { get; set; } diff --git a/EHEC_Server/EHEC_Server/Service.svc.cs b/EHEC_Server/EHEC_Server/Service.svc.cs index 3cc96ff..1929758 100644 --- a/EHEC_Server/EHEC_Server/Service.svc.cs +++ b/EHEC_Server/EHEC_Server/Service.svc.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; +using EHEC_Server.DataBuilder; +using EHEC_Server.DatabaseAccess; namespace EHEC_Server { @@ -11,7 +13,12 @@ namespace EHEC_Server // NOTE: In order to launch WCF Test Client for testing this service, please select Service.svc or Service.svc.cs at the Solution Explorer and start debugging. public class Service : IService { - public List GetDoctors() + public void CreateRandomData(Doctor doctor) + { + Doctor dataaccess = new Doctor(); + dataaccess.CreateDoctors(doctor); + } + public List GetDoctors() { Doctor dataaccess = new Doctor(); return dataaccess.GetAllDoctors(); diff --git a/SQL/EHEC_DB_Query.sql b/SQL/EHEC_DB_Query.sql index 1e5217c..c517592 100644 --- a/SQL/EHEC_DB_Query.sql +++ b/SQL/EHEC_DB_Query.sql @@ -89,7 +89,8 @@ CREATE TABLE [dbo].[Patient] ( [LastName] nvarchar(max) NOT NULL, [BirthDate] datetime NOT NULL, [Street] nvarchar(max) NOT NULL, - [City] nvarchar(max) NOT NULL + [City] nvarchar(max) NOT NULL, + [Region] nvarchar(max) NOT NULL ); GO @@ -98,15 +99,16 @@ CREATE TABLE [dbo].[Doctor] ( [DoctorId] int IDENTITY(1,1) NOT NULL, [FirstName] nvarchar(max) NOT NULL, [LastName] nvarchar(max) NOT NULL, - [DoctorOrigin] nvarchar(max) NOT NULL + [DoctorOrigin] nvarchar(max) NOT NULL, + [Region] nvarchar(max) NOT NULL ); GO -- Creating table 'Origin' CREATE TABLE [dbo].[Origin] ( [OriginId] int IDENTITY(1,1) NOT NULL, - [SicknessId] int NOT NULL, [Name] nvarchar(max) NOT NULL, + [Food] nvarchar(max) NOT NULL, [Street] nvarchar(max) NOT NULL, [City] nvarchar(max) NOT NULL ); @@ -117,8 +119,6 @@ CREATE TABLE [dbo].[Exam] ( [ExamId] int IDENTITY(1,1) NOT NULL, [DoctorId] int NOT NULL, [PatientId] int NOT NULL, - [SicknessStatus] bit NOT NULL, - [SicknessDesignation] nvarchar(max) NOT NULL, [OriginOriginId] int NOT NULL, [Result_ResultId] int NOT NULL ); @@ -128,13 +128,25 @@ GO CREATE TABLE [dbo].[Result] ( [ResultId] int IDENTITY(1,1) NOT NULL, [Name] nvarchar(max) NOT NULL, - [Description] nvarchar(max) NOT NULL +); +GO + +-- Creating table 'Origin_Exam' +CREATE TABLE [dbo].[Origin_Exam] ( + [Origin_ExamId] int IDENTITY(1,1) NOT NULL, + [OriginOriginId] int NOT NULL, + [ExamExamId] int NOT NULL ); GO -- -------------------------------------------------- -- Creating all PRIMARY KEY constraints -- -------------------------------------------------- +-- Creating primary key on [Origin_ExamId] in table 'Origin_Exam' +ALTER TABLE [dbo].[Origin_Exam] +ADD CONSTRAINT [PK_Origin_Exam] + PRIMARY KEY CLUSTERED ([Origin_ExamId] ASC); +GO -- Creating primary key on [PatientId] in table 'Patient' ALTER TABLE [dbo].[Patient] @@ -170,6 +182,9 @@ GO -- Creating all FOREIGN KEY constraints -- -------------------------------------------------- + + + -- Creating foreign key on [Result_ResultId] in table 'Exam' ALTER TABLE [dbo].[Exam] ADD CONSTRAINT [FK_ResultExam] @@ -215,21 +230,37 @@ ON [dbo].[Exam] ([PatientId]); GO --- Creating foreign key on [OriginOriginId] in table 'Exam' -ALTER TABLE [dbo].[Exam] -ADD CONSTRAINT [FK_OriginExam] +-- Creating foreign key on [OriginOriginId] in table 'Origin_Exam' +ALTER TABLE [dbo].[Origin_Exam] +ADD CONSTRAINT [FK_Origin] FOREIGN KEY ([OriginOriginId]) REFERENCES [dbo].[Origin] ([OriginId]) ON DELETE NO ACTION ON UPDATE NO ACTION; GO --- Creating non-clustered index for FOREIGN KEY 'FK_OriginExam' -CREATE INDEX [IX_FK_OriginExam] -ON [dbo].[Exam] +-- Creating non-clustered index for FOREIGN KEY 'FK_Origin_Exam' +CREATE INDEX [IX_FK_Origin_Exam] +ON [dbo].[Origin_Exam] ([OriginOriginId]); GO +-- Creating foreign key on [ExamId] in table 'Origin_Exam' +ALTER TABLE [dbo].[Origin_Exam] +ADD CONSTRAINT [FK_Exam] + FOREIGN KEY ([ExamExamId]) + REFERENCES [dbo].[Exam] + ([ExamId]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_Origin_Exam' +CREATE INDEX [IZ_FK_Origin_Exam] +ON [dbo].[Origin_Exam] + ([ExamExamId]); +GO + + -- -------------------------------------------------- PRINT 'Erfolgreich erstellt..!'; -- Script has ended