Example #1
0
        public void SetBatches(IEnumerable <Batch> batches)
        {
            if (batches == null || !batches.Any())
            {
                return;
            }

            if (batches.Any(p => p.ProducerId != ProducerId))
            {
                throw SheaftException.BadRequest("Une observation est liée au producteur, les lots doivent donc lui être liés.");
            }

            var existingBatchIds = Batches?.Select(b => b.BatchId).ToList() ?? new List <Guid>();
            var newBatchIds      = batches.Select(b => b.Id);
            var batchIdsToRemove = existingBatchIds.Except(newBatchIds);

            if (batchIdsToRemove.Any())
            {
                RemoveBatches(Batches?.Where(b => batchIdsToRemove.Contains(b.BatchId)).Select(b => b.Batch).ToList());
            }

            existingBatchIds = Batches?.Select(b => b.BatchId).ToList() ?? new List <Guid>();
            var batchIdsToAdd = newBatchIds.Except(existingBatchIds);

            if (batchIdsToAdd.Any())
            {
                AddBatches(batches.Where(b => batchIdsToAdd.Contains(b.Id)).ToList());
            }

            Refresh();
        }
        private void ExecuteAllocateBus()
        {
            if (AvailableSeats < RequiredSeats)
            {
                return;
            }
            try
            {
                _people.ForEach(x =>
                {
                    if (SelectedRoute == "Makkah to Madinah")
                    {
                        x.MakkahToMadinahBusNumber = SelectedBus.BusNumber;
                    }
                    else if (SelectedRoute == "Makkah to Airport")
                    {
                        x.MakkahToAirportBusNumber = SelectedBus.BusNumber;
                    }
                    if (SelectedRoute == "Madinah to Airport")
                    {
                        x.MadinahToAirportBusNumber = SelectedBus.BusNumber;
                    }
                    if (SelectedRoute == "Madinah To Makkah")
                    {
                        x.MadinahToMakkahBusNumber = SelectedBus.BusNumber;
                    }
                    _repository.PersonRepository.Update(x);
                });
                _repository.Commit();

                var bus = BusDetails.FirstOrDefault(x => x == SelectedBus);
                bus.Capacity -= RequiredSeats;
                if (bus.Capacity == 0)
                {
                    BusDetails.Remove(bus);
                }

                BusDetails = BusDetails.Where(x => true).ToList();
                MessageBox.Show("Alloted bus number", Constants.Success, MessageBoxButton.OK, MessageBoxImage.Information);

                Batches.Remove(SelectedBatch);
                Batches = Batches.Where(x => true).ToList();

                SelectedBus = null;
            }
            catch
            {
                MessageBox.Show("Could not allot bus number", Constants.Success, MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }