Add a patient model to the server

This commit is contained in:
Andreas Zweili 2018-07-29 12:40:28 +02:00
parent 12b8de2c57
commit 715d581c8a
7 changed files with 133 additions and 1 deletions

View File

@ -9,6 +9,7 @@ namespace Server.DB
public Context() : base("EhecDB") { }
public DbSet<Doctor> Doctors { get; set; }
public DbSet<Person> Persons { get; set; }
public DbSet<Patient> Patients { get; set; }
public DbSet<Exam> Exams { get; set; }
public DbSet<City> Cities { get; set; }
public DbSet<Country> Countries { get; set; }
@ -142,4 +143,4 @@ namespace Server.DB
.HasForeignKey(f => f.FoodPlaceID);
}
}
}
}

View File

@ -0,0 +1,23 @@
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations.Schema;
namespace Server.Models
{
[Table("Patients")]
[DataContract]
public class Patient : Person
{
public Patient() { }
public Patient(string firstName, string lastName, Gender gender, Salutation salutation,
string streetName, string streetNumber, City city)
{
this.FirstName = firstName;
this.LastName = lastName;
this.Gender = gender;
this.Salutation = salutation;
this.StreetName = streetName;
this.StreetNumber = streetNumber;
this.City = city;
}
}
}

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Models;
namespace Server.DB
{
public class PatientDB
{
public ICollection<Patient> GetAllPatients()
{
using (Context ctx = new Context())
{
ctx.Configuration.ProxyCreationEnabled = false;
return ctx.Patients
.Include("Gender")
.Include("City")
.Include("Salutation")
.ToList();
}
}
public bool CreatePatient(Patient doctor)
{
try
{
using (Context ctx = new Context())
{
ctx.Patients.Add(doctor);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdatePatient(Patient doctor)
{
try
{
using (Context ctx = new Context())
{
ctx.Patients.Attach(doctor);
ctx.Entry(doctor).State = System.Data.Entity.EntityState.Modified;
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool DeletePatient(Patient doctor)
{
try
{
using (Context ctx = new Context())
{
ctx.Patients.Attach(doctor);
ctx.Patients.Remove(doctor);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}

View File

@ -36,5 +36,7 @@ namespace Server
ICollection<FoodPlace> GetFoodPlaces();
[OperationContract]
ICollection<PatientAtFoodPlace> GetRelations();
[OperationContract]
ICollection<Patient> GetPatients();
}
}

View File

@ -0,0 +1,23 @@
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations.Schema;
namespace Server.Models
{
[Table("Patients")]
[DataContract]
public class Patient : Person
{
public Patient() { }
public Patient(string firstName, string lastName, Gender gender, Salutation salutation,
string streetName, string streetNumber, City city)
{
this.FirstName = firstName;
this.LastName = lastName;
this.Gender = gender;
this.Salutation = salutation;
this.StreetName = streetName;
this.StreetNumber = streetNumber;
this.City = city;
}
}
}

View File

@ -101,6 +101,7 @@
<Compile Include="DB\ExamDB.cs" />
<Compile Include="DB\GenderDB.cs" />
<Compile Include="DB\PatientAtFoodPlaceDB.cs" />
<Compile Include="DB\PatientDB.cs" />
<Compile Include="DB\PersonDB.cs" />
<Compile Include="DB\SalutationDB.cs" />
<Compile Include="Helper\EntitiesContextInitializer.cs" />
@ -127,6 +128,7 @@
<Compile Include="Models\FoodPlace.cs" />
<Compile Include="Models\Gender.cs" />
<Compile Include="Models\Node.cs" />
<Compile Include="Models\Patient.cs" />
<Compile Include="Models\PatientAtFoodPlace.cs" />
<Compile Include="Models\Person.cs" />
<Compile Include="Models\Salutation.cs" />

View File

@ -91,5 +91,11 @@ namespace Server
StrainDB dataaccess = new StrainDB();
dataaccess.CreateStrain(strain);
}
public ICollection<Patient> GetPatients()
{
PatientDB dataaccess = new PatientDB();
return dataaccess.GetAllPatients();
}
}
}