コード例 #1
0
        /// <summary>
        /// Creates an event. Needs to call a web service ad it will return if there is an existing work order for this asset, otherwise needs to create work order, then event.
        /// </summary>
        /// <returns></returns>
        public ActionResult CreateEvent()
        {
            var mobileWorkOrderFactory = (new TechnicianWorkOrderFactory(Session[Constants.Security.MaintenanceConnectionStringSessionVariableName].ToString(), Session[Constants.Security.ConnectionStringSessionVariableName].ToString()));
            var createModel            = new TechnicianCreateEventModel
            {
                FaultDescriptions = mobileWorkOrderFactory.GetFaultDescriptions(CurrentCity.Id),
                AssetIdOptions    = GetAssetIdOptions()
            };

            return(View(createModel));
        }
コード例 #2
0
        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"));
        }