Beispiel #1
0
        private async System.Threading.Tasks.Task <ObservableCollection <AccidentUtil> > GeetAccidentsToBeHandledAsync()
        {
            List <Accident> accidents;

            using (InsuranceManager.DataAccess.DataContext context = new InsuranceManager.DataAccess.DataContext())
            {
                accidents = await context.Accidents.Where(a => a.Status == Status.ToBeHandled).ToListAsync();
            }
            return(accidents.GetObservable(a =>
            {
                var item = new AccidentUtil(a);
                item.PropertyChanged += HandlerForChange;
                return item;
            }));
        }
        private async System.Threading.Tasks.Task <ObservableCollection <WorkshopUtil> > GetAccidentsAsync()
        {
            List <Workshop> workshops;

            using (InsuranceManager.DataAccess.DataContext context = new InsuranceManager.DataAccess.DataContext())
            {
                workshops = await context.Workshops.Include(t => t.Mechanics.Select(m => m.Tasks)).ToListAsync();
            }

            return(workshops.GetObservable(a =>
            {
                var item = new WorkshopUtil(a);
                return item;
            }));
        }
        private void BtnHandleEvenet_Click(object sender, RoutedEventArgs e)
        {
            TaskUtil task = new TaskUtil();
            uint     days;


            if (uint.TryParse(TxtBoxNumberOfDays.Text, out days))
            {
                if (DateTimePickerStartDate.SelectedDate != null && DateTimePickerStartDate.SelectedDate >= DateTime.Now)
                {
                    task.StartDate = DateTimePickerStartDate.SelectedDate.Value;
                    task.EndDate   = task.StartDate.AddDays(days);
                }
                else
                {
                    MessageBox.Show("Въведи валидна дата");
                    return;
                }
                if (currentMechanic.CanBeAdded(task))
                {
                    using (var context = new InsuranceManager.DataAccess.DataContext())
                    {
                        var mechanic = context.Mechanics.Include(m => m.Tasks).SingleOrDefault(m => m.Id == currentMechanic.Id);
                        var taskDb   = new InsuranceManager.Models.Task
                        {
                            StartDate = task.StartDate,
                            EndDate   = task.EndDate
                        };
                        mechanic?.Tasks?.Add(taskDb);
                        context.SaveChanges();
                        ChangeAccidentProp();
                    }
                    myEventHandler?.Invoke();
                }
                else
                {
                    MessageBox.Show("Две събития се препокриват");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Въведи валидна продължителност");
                return;
            }
        }
Beispiel #4
0
        //Updates database and UI grids EventsToBeHandled and Events that are not Handled
        private async void HandlerForChange(object sender, EventArgs args)
        {
            AccidentUtil accident = (AccidentUtil)sender;

            using (InsuranceManager.DataAccess.DataContext context = new InsuranceManager.DataAccess.DataContext())
            {
                var accidentDb = await context.Accidents.FirstAsync(a => a.Id == accident.ID);

                accidentDb.Status       = (Status)accident.StatusId;
                accidentDb.LastModified = DateTime.Now;
                accident.LastModified   = AccidentUtil.DateToString(accidentDb.LastModified);
                context.SaveChanges();
                if (accidentDb.Status == Status.ToBeHandled && !accidentsToBeHandled.Contains(accident))
                {
                    accidentView.Remove(accident);
                    statistics[0].Value = accidentView.Count;
                    accidentsToBeHandled.Add(accident);
                    statistics[1].Value = accidentsToBeHandled.Count;
                }
            }
        }