Exemplo n.º 1
0
        private void DeleteSlot(DataAccess.DataModels.Slot obj)
        {
            Task.WaitAll(Task.Run(async() => await Load()));
            var updateblock = _blocksList.Find(param => param.ID == obj.BlockID);

            if (updateblock.NumberOfSlots != 0)
            {
                if (MessageBox.Show("Do you want to delete?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Asterisk) == MessageBoxResult.Yes)
                {
                    try
                    {
                        Task.WaitAll(Task.Run(async() => await _slotsRepository.DeleteSlotAsync(obj)));
                        updateblock.NumberOfSlots--;
                        Task.WaitAll(Task.Run(async() => await _blocksRepository.UpdateBlockAsync(updateblock)));
                    }
                    catch
                    {
                        MessageBox.Show("This slot has been using!", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                }
            }

            Task.WaitAll(Task.Run(async() => await Load()));
            SlotsView = new ObservableCollection <DataAccess.DataModels.Slot>();
            if (SelectedBlock != null)
            {
                SlotsView.AddRange(_slotsList.FindAll(param => param.BlockID == $"HCMUTEPL{SelectedBlock.ToString()}"));
            }
            else
            {
                SlotsView.AddRange(_slotsList.GetRange(0, _slotsList.Count));
            }
        }
Exemplo n.º 2
0
        private void Add()
        {
            Task.WaitAll(Task.Run(async() => await Load()));
            if (Block == null || Status == null || InputName == String.Empty || InputName == null)
            {
                MessageBox.Show("You must fill in all fields first!", "Notification", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                return;
            }
            var temp = InputName.Insert(0, Block);

            if (!CheckInputName(temp))
            {
                MessageBox.Show("Name has existed, choose other name!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            DataAccess.DataModels.Slot item = new DataAccess.DataModels.Slot
            {
                ID           = $"HCMUTEPL{temp}",
                Name         = temp,
                Status       = Status,
                Availability = "Yes",
                BlockID      = $"HCMUTEPL{Block}"
            };

            var updateblock = _blocksList.Find(param => param.ID == item.BlockID);

            updateblock.NumberOfSlots++;

            var task1 = Task.Run(async() => await _blocksRepository.UpdateBlockAsync(updateblock));

            var task2 = Task.Run(async() => await _slotsRepository.AddSlotAsync(item));

            Task.WaitAll(task1, task2);
            InputName = String.Empty;
            MessageBox.Show("Slot has been added!", "Successful", MessageBoxButton.OK, MessageBoxImage.Asterisk);
        }