You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
2.8 KiB
105 lines
2.8 KiB
|
3 years ago
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Text;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
|
||
|
|
namespace w230415_classes
|
||
|
|
{
|
||
|
|
public class Hall
|
||
|
|
{
|
||
|
|
public string Name { get; set; }
|
||
|
|
|
||
|
|
protected List<HallPlace> HallPlaceList { get; set; } = new List<HallPlace>();
|
||
|
|
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Read [R]
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
public List<HallPlace> GetNotBookedPlaceList()
|
||
|
|
{
|
||
|
|
List<HallPlace> hpl = new List<HallPlace>();
|
||
|
|
foreach (var item in HallPlaceList)
|
||
|
|
{
|
||
|
|
if (item.FlagBooked) continue;
|
||
|
|
hpl.Add(item);
|
||
|
|
}
|
||
|
|
return hpl;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Read [R]
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="iRow"></param>
|
||
|
|
/// <param name="iPosition"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public HallPlace? ReadPlace(int iRow, int iPosition)
|
||
|
|
{
|
||
|
|
var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow);
|
||
|
|
return el;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Update [U]
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="iRow"></param>
|
||
|
|
/// <param name="iPosition"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public bool BookPlace(int iRow, int iPosition)
|
||
|
|
{
|
||
|
|
var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow);
|
||
|
|
if (el == null)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (el.FlagBooked)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
el.FlagBooked = true;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Create [C]
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="iRow"></param>
|
||
|
|
/// <param name="iPosition"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public bool AddPlace(int iRow, int iPosition)
|
||
|
|
{
|
||
|
|
var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow);
|
||
|
|
if (el != null)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
HallPlaceList.Add(new HallPlace()
|
||
|
|
{
|
||
|
|
SeatPosition = iPosition,
|
||
|
|
SeatRow = iRow,
|
||
|
|
});
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Delete [D]
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="iRow"></param>
|
||
|
|
/// <param name="iPosition"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public bool DeletePlace(int iRow, int iPosition)
|
||
|
|
{
|
||
|
|
var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow);
|
||
|
|
if (el == null)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return HallPlaceList.Remove(el);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|