private void OnRemoveSeat() { if (SelectedSpot != null) { Spot spot = SelectedSpot; ConfirmationBox cb = new ConfirmationBox { Message = String.Format( "Вы действительно желаете удалить место № {0}, {1}, {2}, {3} ряд, {4} место из списка выбранных мест?", spot.Id, spot.SideName, spot.SectorName, spot.RowNum, spot.SeatNum) }; bool?result = cb.ShowDialog(); if (result ?? false) { // First we release all the selected seats List <Seat> seats = ReleaseSeats(SelectedSpots.ToArray()); if (seats != null) { // Then we remove a seat from selected seats collection SelectedSpots.Remove(spot); // and mark spot as unselected on the map foreach (Spot s in Spots) { if (s.Id == spot.Id) { s.IsSelected = false; s.Width = 20; s.Height = 20; } } // At last we again lock seats if (SelectedSpots.Count > 0) { LockSeats(SelectedSpots.ToArray()); } } } } }
/// <summary> /// Locks seats /// </summary> private void LockSeats(Spot[] spots) { List <Seat> seats = new List <Seat>(); foreach (Spot spot in spots) { Seat seat = new Seat(); seat.Id = spot.Id; seat.ReserveDate = ReserveDate; seats.Add(seat); } List <Seat> lockedSeats = Data.Access.LockSeats(seats); if (lockedSeats != null) { HashSet <int> writerIds = new HashSet <int>(lockedSeats.Select(x => x.Id)); seats.RemoveAll(x => writerIds.Contains(x.Id)); foreach (Seat s in seats) { SelectedSpots.Remove(SelectedSpots.Single(i => i.Id == s.Id)); Spots.Remove(Spots.Single(i => i.Id == s.Id)); } int counter = 0; decimal price = 0; foreach (Spot spot in SelectedSpots) { counter++; price += spot.Price; spot.ItemId = counter; } StatusText = String.Format("Удерживается {0} мест на сумму {1}", SeatsCount.ToString("### ##0"), SeatsAmount.ToString("C0")); OperationResult = String.Format("Выбрано мест {0} на сумму {1}", counter, price.ToString("C")); } }