Exemple #1
0
 public void BtnSaveEmployeeChanges()
 {
     using (var ctx = new DatabaseDir.Database())
     {
         ctx.Employees.Attach(SelectedEmployee);
         ctx.Entry(SelectedEmployee).State = EntityState.Modified;
         ctx.SaveChanges();
         new Notification(Notification.NotificationType.Edited, $"{SelectedEmployee.Fullname} er blevet opdateret i databasen.");
     }
 }
Exemple #2
0
        public void BtnAddNewRoute()
        {
            if (NewRoute.Distance < 1)
            {
                new Notification(Notification.NotificationType.Error, "Distancen kan ikke være mindre end 1");
                return;
            }

            Task.Run(() =>
            {
                // Make sure the entered rate value is valid compared to the distance
                double calculatedRate = (NewRoute.LinkedWorkplace.MaxPayout / NewRoute.Distance);
                bool isValid          = (calculatedRate <= StateRouteRate);
                if (!isValid)
                {
                    new Notification(Notification.NotificationType.Error, $"Satsen {calculatedRate},- DKK/km overskrider statens takst {StateRouteRate},- DDK/km");
                    NewRoute.RateValue = StateRouteRate;
                }
                else
                {
                    NewRoute.RateValue = calculatedRate;
                }

                using (var ctx = new DatabaseDir.Database())
                {
                    ctx.Routes.Add(NewRoute);
                    ctx.Entry(NewRoute.LinkedWorkplace).State = EntityState.Detached;
                    ctx.SaveChanges();
                    // Reload the virtual property again.
                    ctx.Entry(NewRoute).Reference(c => c.LinkedWorkplace).Load();

                    SelectedEmployee.Routes.Add(NewRoute);
                    NewRoute            = new Route();
                    NewRoute.EmployeeID = SelectedEmployee.Id;
                    new Notification(Notification.NotificationType.Added, $"Ruten er blevet tilføjet i databasen.");
                    SelectedWorkplace = null;
                    NotifyOfPropertyChange(() => RouteCollection);
                }
            });
        }
Exemple #3
0
 public void BtnDeleteSelectedRoute()
 {
     Task.Run(() =>
     {
         using (var ctx = new DatabaseDir.Database())
         {
             ctx.Routes.Attach(SelectedRoute);
             ctx.Entry(SelectedRoute).State = EntityState.Deleted;
             ctx.SaveChanges();
             new Notification(Notification.NotificationType.Removed, "Den valgte rute er blevet fjernet fra databasen.");
             SelectedEmployee.Routes.Remove(SelectedRoute);
             SelectedRoute = null;
             NotifyOfPropertyChange(() => RouteCollection);
         }
     });
 }
Exemple #4
0
 public void BtnFireSelectedEmployee()
 {
     Task.Run(() =>
     {
         using (var ctx = new DatabaseDir.Database())
         {
             // Flip the fired status of the employee and update the database
             SelectedEmployee.IsFired = !SelectedEmployee.IsFired;
             ctx.Employees.Attach(SelectedEmployee);
             ctx.Entry(SelectedEmployee).State = EntityState.Modified;
             ctx.SaveChanges();
             NotifyOfPropertyChange(() => TitleInformation);
             new Notification(Notification.NotificationType.Edited, $"{SelectedEmployee.Fullname} er blevet opdateret i databasen.");
         }
     });
 }