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

74 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Service_Server.Models;
using System.Web;
namespace Service_Server.DB
{
public class Exam_DB
{
public List<Exam> GetAllExams()
{
using (DATABASE ctx = new DATABASE())
{
return ctx.Exams.ToList();
}
}
public bool CreateExam(Exam exam)
{
try
{
using (DATABASE ctx = new DATABASE())
{
ctx.Exams.Add(exam);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdateExam(Exam exam)
{
try
{
using (DATABASE ctx = new DATABASE())
{
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 (DATABASE ctx = new DATABASE())
{
ctx.Exams.Attach(exam);
ctx.Exams.Remove(exam);
ctx.SaveChanges();
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}