public void MakeMovingTask([FromBody] dynamic json) { dynamic temp = JsonConvert.DeserializeObject(json.ToString()); Moving moving = PopulateMovingTask(temp, new Moving()); moving.WasInspection = false; moving.WasOffer = false; database.Tasks.Add(moving); database.SaveChanges(); }
public void MakeInspectionReport([FromBody] dynamic json) { dynamic temp = JsonConvert.DeserializeObject(json.ToString()); InspectionReport inspectionReport = PopulateInspectionReport(temp); Moving tempmoving = new Moving(); tempmoving.Phase = 1; tempmoving.InspectionReport = inspectionReport; database.Tasks.Add(tempmoving); database.SaveChanges(); }
public void MakeOffer([FromBody] dynamic json) { dynamic temp = JsonConvert.DeserializeObject(json.ToString()); Offer offer = PopulateOffer(temp); Moving task = new Moving(); task.Phase = 2; task.Offer = offer; task.Offer.WithPacking = temp.WithPacking; task.Offer.WasInspection = false; int lentBoxes = temp.Lentboxes; int expectedHours = temp.ExpectedHours; task.Offer.Lentboxes = lentBoxes; task.Offer.ExpectedHours = expectedHours; database.Tasks.Add(task); database.SaveChanges(); }
public void MakeFromInspectionReport([FromBody] dynamic json) { dynamic temp = JsonConvert.DeserializeObject(json.ToString()); Offer offer = PopulateOffer(temp); int inspectionID = temp.InspectionReportID; Moving task = (Moving)database.Tasks.FirstOrDefault(t => t.InspectionReport.ID == inspectionID); task.Phase = 2; task.Offer = offer; task.Offer.InspectionReportID = temp.InspectionReportID; task.Offer.WithPacking = temp.WithPacking; task.Offer.WasInspection = true; int lentBoxes = temp.Lentboxes; int expectedHours = temp.ExpectedHours; task.Offer.Lentboxes = lentBoxes; task.Offer.ExpectedHours = expectedHours; database.Tasks.Update(task); database.SaveChanges(); }
public void MakeMovingTaskFromInspectionReport([FromBody] dynamic json) { dynamic temp = JsonConvert.DeserializeObject(json.ToString()); int inspectionID = temp.ID; Moving tempMoving = (Moving)database.Tasks.FirstOrDefault(i => i.InspectionReport.ID == inspectionID); Moving moving = PopulateMovingTask(temp, tempMoving); tempMoving = moving; tempMoving.Phase = 3; InspectionReport tempInspection = database.Inspections.FirstOrDefault(i => i.ID == inspectionID); tempMoving.InspectionReport = tempInspection; //int inspectionID = temp.InspectionReportID; //tempMoving.InspectionReport = database.Inspections.FirstOrDefault(i => i.ID == inspectionID); tempMoving.WasInspection = true; tempMoving.WasOffer = false; database.Tasks.Update(tempMoving); database.SaveChanges(); }
public SystemControl() { using (var db = new HasserisDbContext()) { db.Database.EnsureDeleted(); db.Database.EnsureCreated(); Employee tempEmployee = new Employee("Christopher", "Chollesen", "AdminPlus", 120, new ContactInfo("*****@*****.**", "41126263"), new Address("Sohngaardsholmparken", "9000", "Aalborg", "Til højre")); tempEmployee.AddLoginInfo("Cholle", "Cholle17"); tempEmployee.IsAvailable = true; Employee tempEmployee_one = new Employee("Jakob", "Østenkjær", "AdminPlus", 150, new ContactInfo("*****@*****.**", "28943519"), new Address("Herningvej", "9220", "Aalborg", "Til højre")); tempEmployee_one.AddLoginInfo("Snuuby", "Jakob17"); tempEmployee_one.IsAvailable = true; Employee tempEmployee_jakob = new Employee("Jacob", "Hasseris", "AdminPlus", 210, new ContactInfo("*****@*****.**", "30103010"), new Address("HasserisVej", "9220", "Aalborg", "Til højre")); tempEmployee_one.AddLoginInfo("Jacob", "Jacob17"); tempEmployee_one.IsAvailable = true; db.Employees.Add(tempEmployee_jakob); Employee tempEmployee_two = new Employee("Kristian", "Eriksen", "AdminPlus", 150, new ContactInfo("*****@*****.**", "50734649"), new Address("Herningvej", "9220", "Aalborg", "Til højre")); tempEmployee_two.AddLoginInfo("Kristian", "Kristian17"); tempEmployee_two.IsAvailable = true; Employee tempEmployee_three = new Employee("Daniel", "Heilskov", "AdminPlus", 150, new ContactInfo("*****@*****.**", "42438049"), new Address("Herningvej", "9220", "Aalborg", "Til højre")); tempEmployee_three.AddLoginInfo("Daniel", "Daniel17"); tempEmployee_three.IsAvailable = true; Employee tempEmployee_four = new Employee("Simon", "Kanne", "AdminPlus", 150, new ContactInfo("*****@*****.**", "61466211"), new Address("Herningvej", "9220", "Aalborg", "Til højre")); tempEmployee_four.AddLoginInfo("Simon", "Simon17"); tempEmployee_four.IsAvailable = true; Employee tempEmployee_five = new Employee("Mathias", "Møller", "AdminPlus", 150, new ContactInfo("*****@*****.**", "93958200"), new Address("Herningvej", "9220", "Aalborg", "Til højre")); tempEmployee_five.AddLoginInfo("Mathias", "Møller17"); tempEmployee_five.IsAvailable = true; Employee tempEmployee_six = new Employee("Andreas", "Nichum", "Employee", 150, new ContactInfo("*****@*****.**", "24840884"), new Address("Herningvej", "9220", "Aalborg", "Til højre")); tempEmployee_six.AddLoginInfo("Andreas", "Andreas17"); tempEmployee_six.IsAvailable = true; Customer tempCustomer = new Private("Erik", "Larsen", new Address("Aalborg Vej", "9220", "Aalborg", "Første dør til højre"), new ContactInfo("*****@*****.**", "23131313")); Customer tempCustomer_one = new Public(new Address("Aalborghusvej", "9110", "Aalborg", "Anden dør"), new ContactInfo("*****@*****.**", "23131313"), "Hasseris Flytteforetning", "123123123123"); Furniture tempFurniture = new Furniture("Sofa møbel", 10, "Sofa", 10); Equipment testEquipment = new Vehicle("Stor lastbil", "Opel", "13131313"); Equipment testEquipment_one = new Vehicle("Alimndelig bil", "Citroen", "13131313"); testEquipment.IsAvailable = true; testEquipment_one.IsAvailable = true; List <DateTime> testList = new List <DateTime>() { new DateTime(2019, 11, 13), new DateTime(2019, 11, 14) }; List <DateTime> testList_two = new List <DateTime>() { new DateTime(2019, 11, 03), new DateTime(2019, 11, 04) }; Delivery tempDelivery = new Delivery("Test Delivery", tempCustomer, new Address("Hasseris vej", "9220", "Aalborg", "Tredje dør til venstre"), 600, testList, "Giv erik noget", "28313131", "Foam", 5, 3); foreach (DateTime date in testList) { PauseTimes temp = new PauseTimes(); temp.Date = date; tempDelivery.PauseTimes.Add(temp); } Moving tempMoving = new Moving("Test Moving", tempCustomer_one, new Address("Kukux vej", "9000", "Aalborg", "første dør til venstre"), 700, testList_two, "Hjælp Lars med at flytte", "23131343", tempCustomer_one.Address, 5, true, 3); tempMoving.Furnitures.Add(tempFurniture); foreach (DateTime date in testList_two) { PauseTimes temp = new PauseTimes(); temp.Date = date; tempMoving.PauseTimes.Add(temp); } tempMoving.Equipment.Add(new TaskAssignedEquipment() { Equipment = testEquipment }); tempMoving.Equipment.Add(new TaskAssignedEquipment() { Equipment = testEquipment_one }); tempMoving.Employees.Add(new TaskAssignedEmployees() { Employee = tempEmployee }); tempMoving.Employees.Add(new TaskAssignedEmployees() { Employee = tempEmployee_five }); tempMoving.Employees.Add(new TaskAssignedEmployees() { Employee = tempEmployee_one }); tempDelivery.Employees.Add(new TaskAssignedEmployees() { Employee = tempEmployee_six }); tempDelivery.Employees.Add(new TaskAssignedEmployees() { Employee = tempEmployee_two }); tempDelivery.Equipment.Add(new TaskAssignedEquipment() { Equipment = testEquipment_one }); db.Tasks.Add(tempDelivery); db.Tasks.Add(tempMoving); db.SaveChanges(); /* * db.Employees.Add(tempEmployee); * db.Employees.Add(tempEmployee_one); * db.Employees.Add(tempEmployee_two); * db.Employees.Add(tempEmployee_three); * db.Employees.Add(tempEmployee_four); * db.Employees.Add(tempEmployee_five); * db.Employees.Add(tempEmployee_six); * * db.Customers.Add(tempCustomer); * db.Customers.Add(tempCustomer_one); * * db.Equipment.Add(testEquipment); * db.Equipment.Add(testEquipment_one); * db.Furniture.Add(tempFurniture); */ foreach (Task ctxTask in db.Tasks) { Console.WriteLine($"{ctxTask.Name}:"); if (ctxTask.Customer is Private) { Console.WriteLine($"{ctxTask.Customer.ID}: {((Private)ctxTask.Customer).Firstname} {((Private)ctxTask.Customer).Lastname}"); } else if (ctxTask.Customer is Business) { Console.WriteLine($"{ctxTask.Customer.ID}: {((Business)ctxTask.Customer).Name}"); } else { Console.WriteLine($"{((Public)ctxTask.Customer).ID}: {((Public)ctxTask.Customer).Name}"); } foreach (var employee in ctxTask.Employees.Select(e => e.Employee)) { Console.WriteLine($"{employee.ID}: {employee.Firstname} {employee.Lastname}"); } foreach (var equipment in ctxTask.Equipment.Select(e => e.Equipment)) { Console.WriteLine($"{equipment.ID}: {equipment.Name}"); } if (ctxTask is Moving) { Console.WriteLine($"Furniture:"); foreach (var furniture in ((Moving)ctxTask).Furnitures) { Console.WriteLine($"{furniture.ID}: {furniture.Name}"); } } Console.WriteLine($"Date(s): "); foreach (var date in ctxTask.Dates) { Console.WriteLine($" {date.Date.DayOfYear}"); } } var test = db.Employees.FirstOrDefault(); Console.WriteLine(test.ContactInfo.Email); } }
public Moving PopulateMovingTask(dynamic temp, Moving movingtask) { string Saddress = temp.StartAddress; string SZIP = temp.StartZIP; string SCity = temp.StartCity; //destination string Daddress = temp.DestinationAddress; string DZIP = temp.DestinationZIP; string DCity = temp.DestinationCity; string notes = temp.Notes; Address startingAddress = new Address(Saddress, SZIP, SCity); Address destination = new Address(Daddress, DZIP, DCity); movingtask.StartingAddress = startingAddress; movingtask.Destination = destination; int customerID = temp.CustomerID; int employeeID = temp.EmployeeID; int carID = temp.CarID; bool withPacking; if (temp.WithPacking != null) { withPacking = true; } else { withPacking = false; } Customer tempCustomer = database.Customers.FirstOrDefault(cus => cus.ID == customerID); Employee tempEmployee = database.Employees.FirstOrDefault(emp => emp.ID == employeeID); Vehicle tempCar = database.Equipment.OfType <Vehicle>().FirstOrDefault(car => car.ID == carID); movingtask.Customer = tempCustomer; Tool tempTool; string name; if (tempCustomer.GetType() == typeof(Private)) { Private cus = (Private)tempCustomer; name = cus.Firstname + ' ' + cus.Lastname; } else if (tempCustomer.GetType() == typeof(Public)) { Public cus = (Public)tempCustomer; name = cus.Name; } else { Business cus = (Business)tempCustomer; name = cus.Name; } int lentBoxes = temp.Lentboxes; string inspection = temp.InspectionDate; string moving = temp.MovingDate; DateTime inspectionDate = DateTime.Parse(inspection, CultureInfo.GetCultureInfo("sv-SE")); DateTime movingDate = DateTime.Parse(moving, CultureInfo.GetCultureInfo("sv-SE")); DateTime endDate = movingDate.AddHours(2); List <DateTime> tempDates = new List <DateTime>(); tempDates.Add(movingDate); tempDates.Add(endDate); movingtask.Name = name + "'s opgave"; movingtask.Income = 0; foreach (DateTime date in tempDates) { DateTimes tempdate = new DateTimes(); tempdate.Date = date; movingtask.Dates.Add(tempdate); } movingtask.Description = notes; movingtask.LentBoxes = lentBoxes; movingtask.WithPacking = withPacking; movingtask.Phase = 3; if (temp.ToolID != null) { int toolID = temp.ToolID; tempTool = database.Equipment.OfType <Tool>().FirstOrDefault(tool => tool.ID == toolID); movingtask.Equipment.Add(new TaskAssignedEquipment() { Equipment = tempTool }); } movingtask.Equipment.Add(new TaskAssignedEquipment() { Equipment = tempCar }); movingtask.Employees.Add(new TaskAssignedEmployees() { Employee = tempEmployee }); return(movingtask); }