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(); } }
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(); * } * } */ }
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(); } } } }
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(); } }
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(); } }
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(); } }
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(); } } }
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(); } } }
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(); } } }
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(); } }
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(); } }
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(); } }
/* * 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(); } }