Exemple #1
0
 public static void AddWorker(Worker workerToAdd)
 {
     using (STOContext db = new STOContext())
     {
         db.Workers.Add(workerToAdd);
         db.SaveChanges();
     }
 }
Exemple #2
0
 public static void AddOwner(Owner ownerToAdd)
 {
     using (STOContext db = new STOContext())
     {
         db.Owners.Add(ownerToAdd);
         db.SaveChanges();
     }
 }
Exemple #3
0
 public static void AddCar(Car car)
 {
     using (STOContext db = new STOContext())
     {
         db.Cars.Add(car);
         db.SaveChanges();
     }
 }
Exemple #4
0
 public static void DeleteOwner(Owner ownerToDelete)
 {
     using (STOContext db = new STOContext())
     {
         if (ownerToDelete != null)
         {
             db.Owners.Remove(ownerToDelete);
             db.SaveChanges();
         }
     }
 }
Exemple #5
0
 public static void UpdataOwner(Owner owner)
 {
     using (STOContext db = new STOContext())
     {
         if (owner != null)
         {
             db.Owners.Update(owner);
             db.SaveChanges();
         }
     }
 }
Exemple #6
0
 public static void DeleteWorker(Worker workerToDelete)
 {
     using (STOContext db = new STOContext())
     {
         if (workerToDelete != null)
         {
             db.Workers.Remove(workerToDelete);
             db.SaveChanges();
         }
     }
 }
Exemple #7
0
 public static void UpdataWorker(Worker worker)
 {
     using (STOContext db = new STOContext())
     {
         if (worker != null)
         {
             db.Workers.Update(worker);
             db.SaveChanges();
         }
     }
 }
Exemple #8
0
 public static void DeleteCar(Car car)
 {
     using (STOContext db = new STOContext())
     {
         if (car != null)
         {
             db.Cars.Remove(car);
             db.SaveChanges();
         }
     }
 }
Exemple #9
0
 public static void UpdataCar(Car car)
 {
     using (STOContext db = new STOContext())
     {
         if (car != null)
         {
             db.Cars.Update(car);
             db.SaveChanges();
         }
     }
 }
Exemple #10
0
        private static void InitializeOrders(STOContext db, int ordersNumber, int carsNumber, int workersNumber)
        {
            //проверка, занесены ли данные в Orders
            if (db.Orders.Any())
            {
                return; //бд иницилизирована
            }

            int      carID;
            DateTime dateReceipt;
            DateTime?dateCompletion;
            int      workerID;

            Random randomObj = new Random(DateTime.Now.Month * 30 + DateTime.Now.Year * 365 + DateTime.Now.Day
                                          + DateTime.Now.Minute);

            for (int OrderID = 1; OrderID <= ordersNumber; OrderID++)
            {
                var date = new DateTime(randomObj.Next(2000, 2020),
                                        randomObj.Next(1, 12),
                                        randomObj.Next(1, 28));
                carID       = db.Cars.Skip(randomObj.Next(0, db.Cars.Count() - 2)).First().CarID;
                dateReceipt = date;
                var twoDate = new DateTime(randomObj.Next(1, 10),
                                           randomObj.Next(1, 12),
                                           randomObj.Next(1, 28));
                if (OrderID % 5 == 0)
                {
                    dateCompletion = date.Add(new TimeSpan(twoDate.Ticks));
                }
                else
                {
                    dateCompletion = null;
                }
                workerID = db.Workers.Skip(randomObj.Next(0, db.Workers.Count() - 2)).First().WorkerID;

                db.Orders.Add(new Order
                {
                    CarID          = carID,
                    DateReceipt    = dateReceipt,
                    DateCompletion = dateCompletion,
                    WorkerID       = workerID
                });
            }

            //сохранение изменений в бд, связанную с объектом контекста
            db.SaveChanges();
        }
Exemple #11
0
        private static void InitializeWorkers(STOContext db, int workersNumber)
        {
            //проверка, занесены ли данные в Workers
            if (db.Workers.Any())
            {
                return; //бд иницилизирована
            }

            string   fioWorker;
            DateTime dateOfEmployment;
            DateTime?dateOfDismissal;
            decimal  salary;

            Random randomObj = new Random(1);

            for (int WorkerID = 1; WorkerID <= workersNumber; WorkerID++)
            {
                var date = new DateTime(randomObj.Next(1990, 2018),
                                        randomObj.Next(1, 12),
                                        randomObj.Next(1, 28));
                fioWorker = MyRandom.RandomString(15);
                var twoDate = new DateTime(randomObj.Next(1, 10),
                                           randomObj.Next(1, 12),
                                           randomObj.Next(1, 28));
                if (WorkerID % 5 == 0)
                {
                    dateOfDismissal = date.Add(new TimeSpan(twoDate.Ticks));
                }
                else
                {
                    dateOfDismissal = null;
                }
                dateOfEmployment = date;
                salary           = randomObj.Next(100, 1000);

                db.Workers.Add(new Worker
                {
                    FioWorker        = fioWorker,
                    DateOfDismissal  = dateOfDismissal,
                    DateOfEmployment = dateOfEmployment,
                    Salary           = salary,
                });
            }

            //сохранение изменений в бд, связанную с объектом контекста
            db.SaveChanges();
        }
Exemple #12
0
        private static void InitializeCars(STOContext db, int carsNumber, int ownersNumber)
        {
            //проверка, занесены ли данные в Cars
            if (db.Cars.Any())
            {
                return; //бд иницилизирована
            }

            int    ownerID;
            string model;
            int    power;
            string colour;
            string stateNumber;
            int    yearOfIssue;
            int    bodyNumber;
            int    engineNumber;

            Random randomObj = new Random(1);

            for (int CarID = 1; CarID <= carsNumber; CarID++)
            {
                ownerID      = db.Owners.Skip(randomObj.Next(0, db.Owners.Count() - 2)).First().OwnerID;
                model        = MyRandom.RandomString(10);
                power        = randomObj.Next(10, 100);
                colour       = MyRandom.RandomString(10);
                stateNumber  = MyRandom.RandomString(9);
                yearOfIssue  = randomObj.Next(1, 4);
                bodyNumber   = randomObj.Next(1, 10);
                engineNumber = randomObj.Next(1, 10);

                db.Cars.Add(new Car
                {
                    OwnerID      = ownerID,
                    Model        = model,
                    Power        = power,
                    Colour       = colour,
                    StateNumber  = stateNumber,
                    YearOfIssue  = yearOfIssue,
                    BodyNumber   = bodyNumber,
                    EngineNumber = engineNumber
                });
            }

            //сохранение изменений в бд, связанную с объектом контекста
            db.SaveChanges();
        }
Exemple #13
0
        private static void InitializeOwners(STOContext db, int ownersNumber)
        {
            //проверка, занесены ли данные в Owners
            if (db.Owners.Any())
            {
                return; //бд иницилизирована
            }

            int    ownerID;
            int    driverLicense;
            string fioOwner;
            string adress;
            int    phone;

            Random randomObj = new Random(1);

            for (int OwnerID = 1; OwnerID <= ownersNumber; OwnerID++)
            {
                ownerID       = OwnerID;
                driverLicense = randomObj.Next(1, 3000);
                fioOwner      = MyRandom.RandomString(15);
                adress        = MyRandom.RandomString(15);
                phone         = randomObj.Next(1, 1000000);

                db.Owners.Add(new Owner
                {
                    DriverLicense = driverLicense,
                    FioOwner      = fioOwner,
                    Adress        = adress,
                    Phone         = phone
                });
            }

            //сохранение изменений в бд, связанную с объектом контекста
            db.SaveChanges();
        }