Exemplo n.º 1
0
        public void AddNewClient(bool isPerson, string s1, string s2, string address, string telephone)
        {
            var client = new Client
            {
                Adress    = address,
                Telephone = telephone
            };

            if (isPerson)
            {
                var person = new Person
                {
                    Id      = client.Id,
                    Name    = s1,
                    Surname = s2
                };
                client.Person = person;
            }
            else
            {
                var company = new Company
                {
                    Id   = client.Id,
                    Name = s1,
                    Code = s2
                };
                client.Company = company;
            }

            using (var context = new AutoShopEntities())
            {
                context.Clients.Add(client);
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public void DeleteJob(object jobId)
        {
            using (var context = new AutoShopEntities())
            {
                if (jobId != null)
                {
                    var job = context.Jobs.FirstOrDefault(x => x.Id == (int)jobId);
                    job.Employees.Clear();
                    context.Jobs.Remove(job);
                    context.SaveChanges();
                }
            }

            /*
             * using (var context = new AutoShopEntities())
             *          {
             *                  if (jobId != null)
             *                  {
             *                          var job = context.Jobs.FirstOrDefault(x => x.Id == (int)jobId);
             *
             *                          context.Jobs.Remove(job);
             *                          context.SaveChanges();
             *                  }
             *          }
             */
        }
Exemplo n.º 3
0
        public void CarLeft(object carId)
        {
            using (var context = new AutoShopEntities())
            {
                if (carId != null)
                {
                    var car = context.Cars.FirstOrDefault(x => x.VIN == (string)carId);

                    if (car.Jobs.Any(job => job.Finished == false))
                    {
                        MessageBox.Show("Automobilis turi neuzbaigtu darbu");
                    }
                    else
                    {
                        car.Arrived = false;

                        foreach (Job job in car.Jobs)
                        {
                            job.Employees.Clear();
                        }

                        context.Jobs.RemoveRange(car.Jobs);
                        context.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 4
0
 public void updateCompany(int id, String name, String code)
 {
     using (var context = new AutoShopEntities())
     {
         Company result = context.Companies.FirstOrDefault(x => x.Id == id);
         result.Name = name;
         result.Code = code;
         context.SaveChanges();
     }
 }
Exemplo n.º 5
0
 public void updatePerson(int id, String name, String surname)
 {
     using (var context = new AutoShopEntities())
     {
         Person result = context.People.FirstOrDefault(x => x.Id == id);
         result.Name    = name;
         result.Surname = surname;
         context.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public void updateClient(int id, String address, String phone)
 {
     using (var context = new AutoShopEntities())
     {
         Client result = context.Clients.FirstOrDefault(x => x.Id == id);
         result.Adress    = address;
         result.Telephone = phone;
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
        public void CarArrived(object carId)
        {
            using (var context = new AutoShopEntities())
            {
                if (carId != null)
                {
                    var car = context.Cars.FirstOrDefault(x => x.VIN == (string)carId);
                    car.Arrived = true;

                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 8
0
        public void FinishJob(object jobId)
        {
            using (var context = new AutoShopEntities())
            {
                if (jobId != null)
                {
                    var job = context.Jobs.FirstOrDefault(x => x.Id == (int)jobId);
                    job.Finished = true;

                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 9
0
        public void AddEmployeeToJob(object employeeId, object jobId)
        {
            using (var context = new AutoShopEntities())
            {
                var employee = context.Employees.FirstOrDefault(x => x.Id == (int)employeeId);
                if (jobId != null)
                {
                    var job = context.Jobs.FirstOrDefault(x => x.Id == (int)jobId);

                    job.Employees.Add(employee);

                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 10
0
        public void AddNewService(string name, string price, string hours)
        {
            var service = new Service
            {
                Name          = name,
                Price         = double.Parse(price),
                Default_hours = double.Parse(hours)
            };

            using (var context = new AutoShopEntities())
            {
                context.Services.Add(service);
                context.SaveChanges();
            }
        }
Exemplo n.º 11
0
        public void AddJobToCar(int serviceId, string carVin)
        {
            using (var context = new AutoShopEntities())
            {
                double hours = (from c in context.Services
                                where c.Id == serviceId
                                select c.Default_hours).FirstOrDefault();

                var job = new Job
                {
                    Service_Id = serviceId,
                    Car_VIN    = carVin,
                    Start      = System.DateTime.Now,
                    Hours      = hours,
                    Finished   = false
                };

                context.Jobs.Add(job);
                context.SaveChanges();
            }
        }
Exemplo n.º 12
0
        public void AddNewCar(string carVIN, string plate, string make, string model, string run, string engine, string year, int clientId)
        {
            var car = new Car
            {
                VIN         = carVIN,
                NumberPlate = plate,
                Make        = make,
                Model       = model,
                Run         = int.Parse(run),
                Engine      = engine,
                Year        = int.Parse(year)
            };

            car.Client_Id = clientId;

            using (var context = new AutoShopEntities())
            {
                context.Cars.Add(car);
                context.SaveChanges();
            }
        }
Exemplo n.º 13
0
        /*
         *      public void PopulateListBoxJobEmployees(ListBox listBoxJobEmployees, ListBox listBoxCarJobs)
         *      {
         *              using (var context = new AutoShopEntities())
         *              {
         *                      if (listBoxCarJobs.SelectedValue != null)
         *                      {
         *                              var results = (from e in context.Employees
         *                                                         where e.Jobs.Any(j => j.Id == (int)listBoxCarJobs.SelectedValue)
         *                                                         select new { Id = e.Id, Row = e.Name + " " + e.Surname }).ToList();
         *
         *                              listBoxJobEmployees.DataSource = results;
         *                              listBoxJobEmployees.DisplayMember = "Row";
         *                              listBoxJobEmployees.ValueMember = "Id";
         *                      }
         *              }
         *      }
         */
        public void addData(object element)
        {
            Type type = element.GetType();

            using (var context = new AutoShopEntities())
            {
                if (type == typeof(Service))
                {
                    context.Services.Add((Service)element);
                }
                if (type == typeof(Car))
                {
                    context.Cars.Add((Car)element);
                }
                if (type == typeof(Employee))
                {
                    context.Employees.Add((Employee)element);
                }
                if (type == typeof(Job))
                {
                    context.Jobs.Add((Job)element);
                }
                if (type == typeof(Client))
                {
                    context.Clients.Add((Client)element);
                }
                if (type == typeof(Company))
                {
                    context.Companies.Add((Company)element);
                }
                if (type == typeof(Person))
                {
                    context.People.Add((Person)element);
                }
                context.SaveChanges();
            }
        }