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;
            }
        }
Ejemplo 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;
                }
            }
        }