Exemplo n.º 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;
            }));
        }
Exemplo n.º 2
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;
                }
            }
        }