oop_NFS_Andreas/Plattform/Plattform/DB/RoomTypeDB.cs

75 lines
1.9 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;
using System.Diagnostics;
namespace Plattform.DB
{
public class RoomTypeDB
{
2018-08-23 21:37:24 +02:00
public List<RoomType> GetAllRoomTypes()
2018-08-19 14:31:58 +02:00
{
using (Context ctx = new Context())
{
return ctx.RoomTypes.ToList();
}
}
2018-08-23 22:47:39 +02:00
public bool CreateRoomType(RoomType roomType)
2018-08-19 14:31:58 +02:00
{
try
{
using (Context ctx = new Context())
{
2018-08-23 22:47:39 +02:00
ctx.RoomTypes.Add(roomType);
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 UpdateRoomType(RoomType roomType)
2018-08-19 14:31:58 +02:00
{
try
{
using (Context ctx = new Context())
{
2018-08-23 22:47:39 +02:00
ctx.RoomTypes.Attach(roomType);
ctx.Entry(roomType).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 DeleteRoomType(RoomType roomType)
2018-08-19 14:31:58 +02:00
{
try
{
using (Context ctx = new Context())
{
2018-08-23 22:47:39 +02:00
ctx.RoomTypes.Attach(roomType);
ctx.RoomTypes.Remove(roomType);
2018-08-19 14:31:58 +02:00
ctx.SaveChanges();
}
return true;
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e);
return false;
}
}
}
}