Add the DB classes for earch model

This commit is contained in:
Andreas Zweili 2018-05-21 14:15:39 +02:00
parent 38ecf02e34
commit 3cc2179f21
11 changed files with 734 additions and 0 deletions

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server.Models;
namespace Server.DB
{
public class CityDB
{
public List<City> GetAllCitys()
{
using (Context ctx = new Context())
{
return ctx.Cities.ToList();
}
}
public bool CreateCity(City city)
{
try
{
using (Context ctx = new Context())
{
ctx.Cities.Add(city);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdateCity(City city)
{
try
{
using (Context ctx = new Context())
{
ctx.Cities.Attach(city);
ctx.Entry(city).State = System.Data.Entity.EntityState.Modified;
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool DeleteCity(City city)
{
try
{
using (Context ctx = new Context())
{
ctx.Cities.Attach(city);
ctx.Cities.Remove(city);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using Server.Models;
namespace Server.DB
{
public class Context : DbContext
{
public Context() : base("EhecDB") { }
public DbSet<Doctor> Doctors { get; set; }
public DbSet<Person> Persons { get; set; }
public DbSet<Exam> Exams { get; set; }
public DbSet<Result> Results { get; set; }
public DbSet<City> Cities { get; set; }
public DbSet<Country> Countries { get; set; }
public DbSet<Salutation> Salutations{ get; set; }
public DbSet<Strain> Strains { get; set; }
public DbSet<Gender> Genders { get; set; }
public DbSet<Status> Status { get; set; }
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server.Models;
namespace Server.DB
{
public class CountryDB
{
public List<Country> GetAllCountrys()
{
using (Context ctx = new Context())
{
return ctx.Countries.ToList();
}
}
public bool CreateCountry(Country country)
{
try
{
using (Context ctx = new Context())
{
ctx.Countries.Add(country);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdateCountry(Country country)
{
try
{
using (Context ctx = new Context())
{
ctx.Countries.Attach(country);
ctx.Entry(country).State = System.Data.Entity.EntityState.Modified;
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool DeleteCountry(Country country)
{
try
{
using (Context ctx = new Context())
{
ctx.Countries.Attach(country);
ctx.Countries.Remove(country);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server.Models;
namespace Server.DB
{
public class DoctorDB
{
public List<Doctor> GetAllDoctors()
{
using (Context ctx = new Context())
{
return ctx.Doctors.ToList();
}
}
public bool CreateDoctor(Doctor doctor)
{
try
{
using (Context ctx = new Context())
{
ctx.Doctors.Add(doctor);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdateDoctor(Doctor doctor)
{
try
{
using (Context ctx = new Context())
{
ctx.Doctors.Attach(doctor);
ctx.Entry(doctor).State = System.Data.Entity.EntityState.Modified;
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool DeleteDoctor(Doctor doctor)
{
try
{
using (Context ctx = new Context())
{
ctx.Doctors.Attach(doctor);
ctx.Doctors.Remove(doctor);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server.Models;
namespace Server.DB
{
public class ExamDB
{
public List<Exam> GetAllExams()
{
using (Context ctx = new Context())
{
return ctx.Exams.ToList();
}
}
public bool CreateExam(Exam exam)
{
try
{
using (Context ctx = new Context())
{
ctx.Exams.Add(exam);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdateExam(Exam exam)
{
try
{
using (Context ctx = new Context())
{
ctx.Exams.Attach(exam);
ctx.Entry(exam).State = System.Data.Entity.EntityState.Modified;
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool DeleteExam(Exam exam)
{
try
{
using (Context ctx = new Context())
{
ctx.Exams.Attach(exam);
ctx.Exams.Remove(exam);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server.Models;
namespace Server.DB
{
public class GenderDB
{
public List<Gender> GetAllGenders()
{
using (Context ctx = new Context())
{
return ctx.Genders.ToList();
}
}
public bool CreateGender(Gender gender)
{
try
{
using (Context ctx = new Context())
{
ctx.Genders.Add(gender);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdateGender(Gender gender)
{
try
{
using (Context ctx = new Context())
{
ctx.Genders.Attach(gender);
ctx.Entry(gender).State = System.Data.Entity.EntityState.Modified;
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool DeleteGender(Gender gender)
{
try
{
using (Context ctx = new Context())
{
ctx.Genders.Attach(gender);
ctx.Genders.Remove(gender);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server.Models;
namespace Server.DB
{
public class PersonDB
{
public List<Person> GetAllPersons()
{
using (Context ctx = new Context())
{
return ctx.Persons.ToList();
}
}
public bool CreatePerson(Person person)
{
try
{
using (Context ctx = new Context())
{
ctx.Persons.Add(person);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdatePerson(Person person)
{
try
{
using (Context ctx = new Context())
{
ctx.Persons.Attach(person);
ctx.Entry(person).State = System.Data.Entity.EntityState.Modified;
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool DeletePerson(Person person)
{
try
{
using (Context ctx = new Context())
{
ctx.Persons.Attach(person);
ctx.Persons.Remove(person);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server.Models;
namespace Server.DB
{
public class ResultDB
{
public List<Result> GetAllResults()
{
using (Context ctx = new Context())
{
return ctx.Results.ToList();
}
}
public bool CreateResult(Result result)
{
try
{
using (Context ctx = new Context())
{
ctx.Results.Add(result);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdateResult(Result result)
{
try
{
using (Context ctx = new Context())
{
ctx.Results.Attach(result);
ctx.Entry(result).State = System.Data.Entity.EntityState.Modified;
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool DeleteResult(Result result)
{
try
{
using (Context ctx = new Context())
{
ctx.Results.Attach(result);
ctx.Results.Remove(result);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server.Models;
namespace Server.DB
{
public class SalutationDB
{
public List<Salutation> GetAllSalutations()
{
using (Context ctx = new Context())
{
return ctx.Salutations.ToList();
}
}
public bool CreateSalutation(Salutation salutation)
{
try
{
using (Context ctx = new Context())
{
ctx.Salutations.Add(salutation);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdateSalutation(Salutation salutation)
{
try
{
using (Context ctx = new Context())
{
ctx.Salutations.Attach(salutation);
ctx.Entry(salutation).State = System.Data.Entity.EntityState.Modified;
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool DeleteSalutation(Salutation salutation)
{
try
{
using (Context ctx = new Context())
{
ctx.Salutations.Attach(salutation);
ctx.Salutations.Remove(salutation);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server.Models;
namespace Server.DB
{
public class StatusDB
{
public List<Status> GetAllStatus()
{
using (Context ctx = new Context())
{
return ctx.Status.ToList();
}
}
public bool CreateStatus(Status status)
{
try
{
using (Context ctx = new Context())
{
ctx.Status.Add(status);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdateStatus(Status status)
{
try
{
using (Context ctx = new Context())
{
ctx.Status.Attach(status);
ctx.Entry(status).State = System.Data.Entity.EntityState.Modified;
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool DeleteStatus(Status status)
{
try
{
using (Context ctx = new Context())
{
ctx.Status.Attach(status);
ctx.Status.Remove(status);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server.Models;
namespace Server.DB
{
public class StrainDB
{
public List<Strain> GetAllStrains()
{
using (Context ctx = new Context())
{
return ctx.Strains.ToList();
}
}
public bool CreateStrain(Strain strain)
{
try
{
using (Context ctx = new Context())
{
ctx.Strains.Add(strain);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdateStrain(Strain strain)
{
try
{
using (Context ctx = new Context())
{
ctx.Strains.Attach(strain);
ctx.Entry(strain).State = System.Data.Entity.EntityState.Modified;
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool DeleteStrain(Strain strain)
{
try
{
using (Context ctx = new Context())
{
ctx.Strains.Attach(strain);
ctx.Strains.Remove(strain);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}