Beispiel #1
0
        /// <summary>
        /// Insert a new Room into the databse.
        /// </summary>
        /// <param name="p_room">The new Room.</param>
        /// <returns>The Newly created Room-Object. NULL, or Exception if an error occurs.</returns>
        public Room Insert(Room p_room)
        {
            using (var context = new FhdwHotelContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var hotel = context.Hotel.SingleOrDefault(h => h.ID == p_room.Hotel.ID);
                        p_room.Hotel = hotel;

                        context.Room.Add(p_room);
                        context.SaveChanges();

                        transaction.Commit();
                        return p_room;
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        transaction.Rollback();
                        return null;
                    }
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Delete a Room.
 /// </summary>
 /// <param name="p_room"></param>
 /// <returns></returns>
 public Room Delete(Room p_room)
 {
     return _roomRepository.Delete(p_room);
 }
Beispiel #3
0
 /// <summary>
 /// Insert or Update a Room depending on the ID.
 /// </summary>
 /// <param name="p_room"></param>
 /// <returns></returns>
 public Room Save(Room p_room)
 {
     return p_room.ID == 0 ? _roomRepository.Insert(p_room) : _roomRepository.Update(p_room);
 }
Beispiel #4
0
        /// <summary>
        /// Delete a room from the database.
        /// </summary>
        /// <param name="p_room">Roomobject with the ID set.</param>
        /// <returns>The deleted Room-Object. NULL, or Exception if an error occurs.</returns>
        public Room Delete(Room p_room)
        {
            using (var context = new FhdwHotelContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var roomToDelete = context.Room.SingleOrDefault(r => r.ID == p_room.ID);

                        context.Room.Remove(roomToDelete);
                        context.SaveChanges();
                        transaction.Commit();

                        return roomToDelete;
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        transaction.Rollback();
                        return null;
                    }
                }
            }
        }