public IActionResult Add(AddTrailerViewModel addTrailerViewModel) { if (ModelState.IsValid) { Trailer newTrailer = new Trailer { SerialNumber = addTrailerViewModel.SerialNumber, TrailerNumber = addTrailerViewModel.TrailerNumber, TrailerMake = addTrailerViewModel.TrailerMake, TrailerModel = addTrailerViewModel.TrailerModel, Year = addTrailerViewModel.Year, InspDate = addTrailerViewModel.InspDate, RegDate = addTrailerViewModel.RegDate, }; //add to tractorData context.Trailers.Add(newTrailer); //always save changes context.SaveChanges(); return(Redirect("/Trailer/")); } ; return(View(addTrailerViewModel)); }
////////////// All DriverTractorHistories will be moved to Driver /////////////////// // this method will Add new driverTractorHistory to driverHistories Table public DriverTractorAssignmentHistory AddHistory(Employee employee, Tractor tractor) { DriverTractorAssignmentHistory history = new DriverTractorAssignmentHistory(employee, tractor); context.DriverTractorsAssignmentHistory.Add(history); context.SaveChanges(); return(history); }
public IActionResult Add(AddOrderViewModel addOrderViewModel) { if (ModelState.IsValid) { Order newOrder = new Order() { OrderNumber = addOrderViewModel.OrderNumber, DueDate = addOrderViewModel.DueDate, //Driver = null, //matches the TrailerForLoad = context.Trailers.Where(x => x.TrailerID == addOrderViewModel.TrailerID).Single(), CustomerOrders = context.Customers.Single(x => x.CustomerID == addOrderViewModel.CustomerID), //Driver = context.Employees.ToList() }; context.Orders.Add(newOrder); trailerSelected = context.Trailers.Where(x => x.TrailerID == addOrderViewModel.TrailerID).Single(); //newOrder.TrailerForLoad = trailerSelected; trailerSelected.TrailerStatus = "Unavailable"; context.SaveChanges(); return(Redirect("/Order")); } return(View(addOrderViewModel)); }
public IActionResult Add(AddCustomerViewModel addCustomerViewModel) { if (ModelState.IsValid) { Customer newCustomer = new Customer { CustomerName = addCustomerViewModel.CustomerName, StreetNumber = addCustomerViewModel.StreetNumber, StreetName = addCustomerViewModel.StreetName, City = addCustomerViewModel.City, ZipCode = addCustomerViewModel.ZipCode, State = addCustomerViewModel.State }; //add to customer data to Customer table context.Customers.Add(newCustomer); //always save changes context.SaveChanges(); return(Redirect("/Customer")); } ; return(View(addCustomerViewModel)); }
// changes the avilablity of particular tractor with id public Tractor ChangeStatusWithId(int id) { Tractor tractorToChangeStatus = context.Tractors.SingleOrDefault(x => x.TractorID == id); if (tractorToChangeStatus.Status == "Available") { tractorToChangeStatus.Status = "Unavailable"; context.SaveChanges(); } else if (tractorToChangeStatus.Status == "Unavailable") { tractorToChangeStatus.Status = "Available"; context.SaveChanges(); } return(tractorToChangeStatus); }
public Employee CreateEmployee(Employee newEmployee) { context.Employees.Add(newEmployee); context.SaveChanges(); return(newEmployee); }