public ActionResult CreateEvent(TechnicianCreateEventModel model, IEnumerable <HttpPostedFileBase> files, FormCollection coll) { var mobileWorkOrderFactory = (new TechnicianWorkOrderFactory(Session[Constants.Security.MaintenanceConnectionStringSessionVariableName].ToString(), Session[Constants.Security.ConnectionStringSessionVariableName].ToString())); //create the work order event in RBAC - //get the selected event code the user chose var eventCode = mobileWorkOrderFactory.GetEventCode(model.SelectedFaultDescription, CurrentCity.Id); if (eventCode == null) { //if we got this far, something failed. add error to model and display to user ModelState.AddModelError(Constants.ViewData.ModelStateStatusKey, (new ResourceFactory()).GetLocalizedTitle(ResourceTypes.StatusMessage, "Event Code not found. Try again.")); //repopulate the options for the lists model.FaultDescriptions = mobileWorkOrderFactory.GetFaultDescriptions(CurrentCity.Id); model.AssetIdOptions = GetAssetIdOptions(); //send them back to the view with the error return(View("CreateEvent", model)); } //first check to see if the selected asset key is valid //message / error handling if needed bool assetIsValid = true; if (string.IsNullOrEmpty(model.SelectedAssetKey) || model.SelectedAssetKey.Split('|').Count() != 3) { //if we got this far, something failed. add error to model and display to user ModelState.AddModelError(Constants.ViewData.ModelStateStatusKey, (new ResourceFactory()).GetLocalizedTitle(ResourceTypes.StatusMessage, "Invalid Asset.")); //repopulate the options for the lists model.FaultDescriptions = mobileWorkOrderFactory.GetFaultDescriptions(CurrentCity.Id); model.AssetIdOptions = GetAssetIdOptions(); //send them back to the view with the error return(View("CreateEvent", model)); } //once it all checks out, create the work order, create the event id, and add the images, then send to the listing page //break out the SelectedAssetKey of the model = CustomerId | AreaId | AssetId var ids = model.SelectedAssetKey.Split('|'); var areaid = ids[1]; var assetid = ids[2]; int areaID = int.Parse(areaid); int assetID = int.Parse(assetid); //create work order var workOrderId = mobileWorkOrderFactory.CreateWorkOrder(assetID, model.SelectedFaultDescription, CurrentCity.Id, areaID, CurrentCity.LocalTime); //get event ID var webServiceFactory = new WebServiceFactory(); //create the event via the web service factory. //create the Create Alarm Request object to pass to the web services var createAlarmRequest = new CreateAlarmRequest { AreaId = areaID, AssetId = assetID, CustomerId = CurrentCity.Id, EventCode = eventCode.EventCode1, EventSource = eventCode.EventSource, LocalTime = CurrentCity.LocalTime, Notes = model.Notes, WorkOrderId = workOrderId }; var createAlarmResponse = webServiceFactory.CreateAlarm(createAlarmRequest); //check the response, if it failed, (eventUID is -1 or slaDue is minvalue if (!createAlarmResponse.IsValid) { //if we got this far, something failed. add error to model and display to user ModelState.AddModelError(Constants.ViewData.ModelStateStatusKey, (new ResourceFactory()).GetLocalizedTitle(ResourceTypes.StatusMessage, "Event could not be created: " + createAlarmResponse.ErrorMessage)); //repopulate the options for the lists model.FaultDescriptions = mobileWorkOrderFactory.GetFaultDescriptions(CurrentCity.Id); model.AssetIdOptions = GetAssetIdOptions(); //send them back to the view with the error return(View("CreateEvent", model)); } //we found the event code, continue. just set the sla to 2 hours int he future, it will be updated below. var workOrderEventId = mobileWorkOrderFactory.CreateWorkOrderEvent(createAlarmResponse.EventUID, workOrderId, eventCode.EventCode1, CurrentCity.LocalTime, eventCode.EventDescVerbose, createAlarmResponse.SlaDue, eventCode.AlarmTier, model.Notes, false, false, (int)WorkOrderEventStatus.Open); //every time a event is created, resolved , etc, we have to update the sladue and highest severity, so lets do that now mobileWorkOrderFactory.UpdateEventAggregateInfo(workOrderId); //now we need to add the images to the work order (if there are any) if (files != null) { foreach (var file in files) { mobileWorkOrderFactory.CreateWorkOrderImage(workOrderId, ImageFactory.StreamToByteArray(file.InputStream), CurrentCity.LocalTime); } } //now that it is created correctly, send them to the listing page so they can see thier new owrk order. return(RedirectToAction("WorkOrders")); }
public ActionResult CreateEventId(DispatcherCreateEventModel model) { //message / error handling if needed //once it all checks out, create the work order, create the event id, then send to the listing page //break out the SelectedAssetKey of the model = CustomerId | AreaId | AssetId var ids = model.SelectedAssetKey.Split('|'); var customerId = ids[0]; var areaid = ids[1]; var assetid = ids[2]; int customerID = int.Parse(customerId); //instantiate the factory with the current maintenance group and the selected city for the asset var selectedCustomer = CurrentCity.MaintenanceCustomers.FirstOrDefault(x => x.Id == customerID); if (selectedCustomer != null) { var workOrderFactory = (new DispatcherWorkOrderFactory(selectedCustomer.PemsConnectionStringName, CurrentCity.MaintenanceConnectionStringName)); //create the work order event in RBAC - //get the selected event code the user chose var eventCode = workOrderFactory.GetEventCode(model.SelectedFaultDescription, selectedCustomer.Id); if (eventCode == null) { //if we got this far, something failed. add error to model and display to user ModelState.AddModelError(Constants.ViewData.ModelStateStatusKey, (new ResourceFactory()).GetLocalizedTitle(ResourceTypes.StatusMessage, "Event Code not found. Try again.")); //repopulate the options for the lists //we have to pull a facotory for each customer, since their conneciton string could be different. foreach (var maintenanceCustomer in CurrentCity.MaintenanceCustomers) { var woFactory = (new DispatcherWorkOrderFactory(maintenanceCustomer)); model.FaultDescriptions.AddRange(woFactory.GetFaultDescriptions(maintenanceCustomer.Id)); var customerAssetOptions = woFactory.GetAssetsForCustomer(maintenanceCustomer.Id); //fix up all the customer names for the asset options customerAssetOptions.ForEach(x => x.CustomerName = maintenanceCustomer.DisplayName); model.AssetIdOptions.AddRange(customerAssetOptions); } //send them back to the view with the error return(View("CreateEventId", model)); } int areaID = int.Parse(areaid); int assetID = int.Parse(assetid); //create work order var workOrderId = workOrderFactory.CreateWorkOrder(assetID, model.SelectedFaultDescription, selectedCustomer.Id, areaID, selectedCustomer.LocalTime, model.CrossStreet, model.Notes); //get event ID var webServiceFactory = new WebServiceFactory(); //create the event via the web service factory. //create the Create Alarm Request object to pass to the web services var createAlarmRequest = new CreateAlarmRequest { AreaId = areaID, AssetId = assetID, CustomerId = selectedCustomer.Id, EventCode = eventCode.EventCode1, EventSource = eventCode.EventSource, LocalTime = selectedCustomer.LocalTime, Notes = model.Notes, WorkOrderId = workOrderId }; var createAlarmResponse = webServiceFactory.CreateAlarm(createAlarmRequest); //check the response, if it failed, (eventUID is -1 or slaDue is minvalue if (!createAlarmResponse.IsValid) { //if we got this far, something failed. add error to model and display to user ModelState.AddModelError(Constants.ViewData.ModelStateStatusKey, (new ResourceFactory()).GetLocalizedTitle(ResourceTypes.StatusMessage, "Event could not be created: " + createAlarmResponse.ErrorMessage)); //repopulate the options for the lists //we have to pull a facotory for each customer, since their conneciton string could be different. foreach (var maintenanceCustomer in CurrentCity.MaintenanceCustomers) { var woFactory = (new DispatcherWorkOrderFactory(maintenanceCustomer)); model.FaultDescriptions.AddRange(woFactory.GetFaultDescriptions(maintenanceCustomer.Id)); var customerAssetOptions = woFactory.GetAssetsForCustomer(maintenanceCustomer.Id); //fix up all the customer names for the asset options customerAssetOptions.ForEach(x => x.CustomerName = maintenanceCustomer.DisplayName); model.AssetIdOptions.AddRange(customerAssetOptions); } //send them back to the view with the error return(View("CreateEventId", model)); } //we found the event code, continue. just set the sla to 2 hours int he future, it will be updated below. var workOrderEventId = workOrderFactory.CreateWorkOrderEvent(createAlarmResponse.EventUID, workOrderId, eventCode.EventCode1, CurrentCity.LocalTime, eventCode.EventDescVerbose, createAlarmResponse.SlaDue, eventCode.AlarmTier, model.Notes, false, false, (int)WorkOrderEventStatus.Open); //every time a event is created, resolved , etc, we have to update the sladue and highest severity, so lets do that now workOrderFactory.UpdateEventAggregateInfo(workOrderId); //now that it is created correctly, send them to the listing page so they can see thier new owrk order. return(RedirectToAction("WorkOrderDetail", "WorkOrders", new { workOrderId })); } //fail here, no customer found, refresh page, add error, whatever //if we got this far, something failed. add error to model and display to user ModelState.AddModelError(Constants.ViewData.ModelStateStatusKey, (new ResourceFactory()).GetLocalizedTitle(ResourceTypes.StatusMessage, "Customer Not Found. Try again.")); //repopulate the options for the lists //we have to pull a facotory for each customer, since their conneciton string could be different. foreach (var maintenanceCustomer in CurrentCity.MaintenanceCustomers) { var woFactory = (new DispatcherWorkOrderFactory(maintenanceCustomer)); model.FaultDescriptions.AddRange(woFactory.GetFaultDescriptions(maintenanceCustomer.Id)); var customerAssetOptions = woFactory.GetAssetsForCustomer(maintenanceCustomer.Id); //fix up all the customer names for the asset options customerAssetOptions.ForEach(x => x.CustomerName = maintenanceCustomer.DisplayName); model.AssetIdOptions.AddRange(customerAssetOptions); } return(View("CreateEventId", model)); }