oop_II-6/Service_Server/Service_Server/DB/Person_DB.cs

74 lines
1.7 KiB
C#

using Service_Server.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace Service_Server.DB
{
public class Person_DB
{
public List<Person> GetAllPersons()
{
using (DATABASE ctx = new DATABASE())
{
return ctx.Persons.ToList();
}
}
public bool CreatePerson(Person person)
{
try
{
using (DATABASE ctx = new DATABASE())
{
ctx.Persons.Add(person);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdatePerson(Person person)
{
try
{
using (DATABASE ctx = new DATABASE())
{
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 (DATABASE ctx = new DATABASE())
{
ctx.Persons.Attach(person);
ctx.Persons.Remove(person);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}