public static void CreateAssist(UIIncidentDispatch incidentDispatch) { using (FSPDataContext dc = new FSPDataContext()) { using (TowTruckServiceRef.TowTruckServiceClient service = new TowTruckServiceRef.TowTruckServiceClient()) { TowTruckServiceRef.IncidentIn thisIncident = new TowTruckServiceRef.IncidentIn(); Guid IncidentID = Guid.NewGuid(); DateTime TimeStamp = DateTime.Now; Guid CreatedBy = MembershipExtensions.GetUserId(); thisIncident.IncidentID = IncidentID; thisIncident.FreewayID = Convert.ToInt32(incidentDispatch.FreewayId); thisIncident.LocationID = dc.Locations.Where(p => p.LocationCode == incidentDispatch.LocationName).FirstOrDefault().LocationID; thisIncident.TimeStamp = TimeStamp; thisIncident.CreatedBy = CreatedBy; thisIncident.Description = incidentDispatch.Description; thisIncident.IncidentNumber = String.Empty; //create incident service.AddIncident(thisIncident); //for each truck create assit foreach (var truck in incidentDispatch.SelectedTrucks) { TowTruckServiceRef.AssistReq thisAssist = new TowTruckServiceRef.AssistReq(); thisAssist.AssistID = Guid.NewGuid(); thisAssist.IncidentID = IncidentID; FleetVehicle dbTruck = dc.FleetVehicles.Where(p => p.VehicleNumber == truck).FirstOrDefault(); thisAssist.FleetVehicleID = dbTruck.FleetVehicleID; thisAssist.ContractorID = dbTruck.ContractorID; thisAssist.DispatchTime = DateTime.Now; thisAssist.x1097 = DateTime.Now; service.AddAssist(thisAssist); } } } }
public ActionResult PostIncidentDispatchAjax(String direction, String freeway, String location, String crossStreet1, String crossStreet2, String comments, string selectedTrucks) { Boolean returnValue = true; try { using (TowTruckServiceRef.TowTruckServiceClient service = new TowTruckServiceRef.TowTruckServiceClient()) { TowTruckServiceRef.IncidentIn thisIncident = new TowTruckServiceRef.IncidentIn(); Guid IncidentID = Guid.NewGuid(); DateTime TimeStamp = DateTime.Now; Guid CreatedBy = MembershipExtensions.GetUserId(); var trucks = new JavaScriptSerializer().Deserialize <IEnumerable <SelectedTruck> >(selectedTrucks); String firstTruckBeatNumber = trucks.FirstOrDefault().beatNumberString; thisIncident.IncidentID = IncidentID; thisIncident.Direction = direction; thisIncident.FreewayID = Convert.ToInt32(freeway); thisIncident.LocationID = dc.Locations.Where(p => p.LocationCode == location).FirstOrDefault().LocationID; thisIncident.BeatSegmentID = new Guid("00000000-0000-0000-0000-000000000000"); thisIncident.BeatNumber = firstTruckBeatNumber; thisIncident.TimeStamp = TimeStamp; thisIncident.CreatedBy = CreatedBy; thisIncident.Description = comments; thisIncident.CrossStreet1 = crossStreet1; thisIncident.CrossStreet2 = crossStreet2; thisIncident.IncidentNumber = String.Empty; thisIncident.Location = "na"; //create incident service.AddIncident(thisIncident); //for each truck create assit foreach (var truck in trucks) { TowTruckServiceRef.AssistReq thisAssist = new TowTruckServiceRef.AssistReq(); thisAssist.AssistID = Guid.NewGuid(); thisAssist.IncidentID = IncidentID; FleetVehicle dbTruck = dc.FleetVehicles.Where(p => p.VehicleNumber == truck.truckNumber).FirstOrDefault(); thisAssist.FleetVehicleID = dbTruck.FleetVehicleID; thisAssist.ContractorID = dbTruck.ContractorID; thisAssist.DispatchTime = DateTime.Now; thisAssist.x1097 = DateTime.Now; service.AddAssist(thisAssist); } } } catch { returnValue = false; } return(Json(returnValue, JsonRequestBehavior.AllowGet)); }