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 HallPlaceList { get; set; } = new List(); /// /// Read [R] /// /// public List GetNotBookedPlaceList() { List hpl = new List(); foreach (var item in HallPlaceList) { if (item.FlagBooked) continue; hpl.Add(item); } return hpl; } /// /// Read [R] /// /// /// /// public HallPlace? ReadPlace(int iRow, int iPosition) { var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow); return el; } /// /// Update [U] /// /// /// /// 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; } /// /// Create [C] /// /// /// /// 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; } /// /// Delete [D] /// /// /// /// 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); } } }