oop_NFS_Andreas/Plattform/Plattform/DB/RoomDB.cs

74 lines
1.8 KiB
C#
Raw Normal View History

2018-08-19 14:31:58 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using Plattform.Models;
namespace Plattform.DB
{
public class RoomDB
{
2018-08-23 21:37:24 +02:00
public List<Room> GetAllRooms()
2018-08-19 14:31:58 +02:00
{
using (Context ctx = new Context())
{
return ctx.Rooms.ToList();
}
}
2018-08-23 22:47:39 +02:00
public bool CreateRoom(Room room)
2018-08-19 14:31:58 +02:00
{
try
{
using (Context ctx = new Context())
{
2018-08-23 22:47:39 +02:00
ctx.Rooms.Add(room);
2018-08-19 14:31:58 +02:00
ctx.SaveChanges();
}
return true;
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e);
return false;
}
}
2018-08-23 22:47:39 +02:00
public bool UpdateRoom(Room room)
2018-08-19 14:31:58 +02:00
{
try
{
using (Context ctx = new Context())
{
2018-08-23 22:47:39 +02:00
ctx.Rooms.Attach(room);
ctx.Entry(room).State = System.Data.Entity.EntityState.Modified;
2018-08-19 14:31:58 +02:00
ctx.SaveChanges();
}
return true;
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e);
return false;
}
}
2018-08-23 22:47:39 +02:00
public bool DeleteRoom(Room room)
2018-08-19 14:31:58 +02:00
{
try
{
using (Context ctx = new Context())
{
2018-08-23 22:47:39 +02:00
ctx.Rooms.Attach(room);
ctx.Rooms.Remove(room);
2018-08-19 14:31:58 +02:00
ctx.SaveChanges();
}
return true;
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e);
return false;
}
}
}
}