private DataResponseHistoricalAlarm MakeClearAlarmsHistoricAlarmsResponse( DataRequestHistoricalAlarm historicAlarmRequest) { //make a response from the request var historicAlarmResponse = new DataResponseHistoricalAlarm { EventUID = historicAlarmRequest.EventUID, statusCode = ClearAlarm(historicAlarmRequest) }; //now create the work order event for this alarm return(historicAlarmResponse); }
private string ClearAlarm(DataRequestHistoricalAlarm historicAlarmRequest) { //clear the work order event const int defaultValue = -1; //first, parse the ids int customeId = int.TryParse(historicAlarmRequest.cid, out customeId) ? customeId : defaultValue; int meterId = int.TryParse(historicAlarmRequest.mid, out meterId) ? meterId : defaultValue; int areaId = int.TryParse(historicAlarmRequest.aid, out areaId) ? areaId : defaultValue; int eventSource = int.TryParse(historicAlarmRequest.EventSource, out eventSource) ? eventSource : defaultValue; int eventCode = int.TryParse(historicAlarmRequest.EventCode, out eventCode) ? eventCode : defaultValue; long eventUID = long.TryParse(historicAlarmRequest.EventUID, out eventUID) ? eventUID : defaultValue; int workOrderId = int.TryParse(historicAlarmRequest.WorkOrderId, out workOrderId) ? workOrderId : defaultValue; //check ot make sure all the ids were parsed correctly if (customeId > defaultValue && meterId > defaultValue && areaId > defaultValue && eventCode > defaultValue && eventSource > defaultValue && eventUID > defaultValue && workOrderId > defaultValue) { var currentCustomer = new PemsCity(customeId.ToString()); //go get the customer so we can get the correct connection string using ( var maintenanceEntities = new MaintenanceEntities(currentCustomer.MaintenanceConnectionStringName)) { //first we have to go to PEMS db to get the asset //return nothing if the asset doesnt exist. var assetFactory = (new AssetFactory(currentCustomer.PemsConnectionStringName)); var asset = assetFactory.GetAsset(customeId, areaId, meterId); //fail state - work order or work order event will not be closed if (asset == null) { return(((int)WorkOrderEventStatus.Open).ToString()); } //close out the work order event //go get the event //check to see if the event exist first var existingWorkOrderEvent = maintenanceEntities.FMWorkOrderEvents.FirstOrDefault( x => x.WorkOrderId == workOrderId && x.EventId == eventUID && x.EventCode == eventCode); //if it doesnt exist, cant close it, just return closed if (existingWorkOrderEvent == null) { return(((int)WorkOrderEventStatus.Closed).ToString()); } //clear the event existingWorkOrderEvent.Status = (int)WorkOrderEventStatus.Closed; maintenanceEntities.SaveChanges(); //every time a event is created, resolved , etc, we have to update the sladue and highest severity, so lets do that now var mobileWorkOrderFactory = (new TechnicianWorkOrderFactory(currentCustomer.MaintenanceConnectionStringName, currentCustomer.PemsConnectionStringName)); mobileWorkOrderFactory.UpdateEventAggregateInfo(workOrderId); //then clear the work order (if its the last event that was open was just closed) CloseWorkOrder(maintenanceEntities, workOrderId, currentCustomer.LocalTime); return(((int)WorkOrderEventStatus.Closed).ToString()); } } //cant find the itme the request was referencing, return closed. //return WorkOrderEventStatus enum representing if it were closed or not. return(((int)WorkOrderEventStatus.Closed).ToString()); }