/// <summary>
        /// Creates a work order in the system for a mobile user (technician)
        /// </summary>
        /// <param name="assetId"></param>
        /// <param name="faultDescription"></param>
        /// <param name="notes"></param>
        /// <param name="customerId"></param>
        /// <param name="areaId"></param>
        /// <param name="localTime"></param>
        /// <returns></returns>
        public long CreateWorkOrder(int assetId, string faultDescription, int customerId, int areaId,
                                    DateTime localTime, string crossStreet, string notes)
        {
            //we have to check to see if htey asset already has a work order. if it does, use that work order. This includes any open, incomplete or rejected work orders.
            //we add it to any open work order, even if it is assigned ot another technician (in practice this will almost never happen)
            var existingWorkOrder =
                MaintenanceEntities.FMWorkOrders.FirstOrDefault(x => x.MeterId == assetId &&
                                                                (x.WorkOrderStatusId == (int)WorkOrderStatus.Open ||
                                                                 x.WorkOrderStatusId == (int)WorkOrderStatus.Incomplete ||
                                                                 x.WorkOrderStatusId == (int)WorkOrderStatus.Rejected));

            if (existingWorkOrder != null)
            {
                return(existingWorkOrder.WorkOrderId);
            }
            //first we have to go to PEMS db to get the asset
            var assetFactory = (new AssetFactory(ConnectionStringName));

            var asset = assetFactory.GetAsset(customerId, areaId, assetId);

            //fail state
            if (asset == null)
            {
                return(-1);
            }

            //create the work order now. commented out properties we ignore upon creation.
            var fmWorkOrder = new FMWorkOrder
            {
                AreaId = areaId,
                //  AssignedDate = localTime, - not set until it is assigned
                CreateDateTime  = localTime,
                CreatedById     = WebSecurity.CurrentUserId,
                CrossStreet     = crossStreet,
                CustomerId      = customerId,
                HighestSeverity = 0,
                Location        = asset.Location,
                Mechanism       = asset.MeterType,
                MeterGroup      = asset.MeterGroup ?? 1,
                MeterId         = assetId,
                Notes           = notes,
                ReportingUserId = WebSecurity.CurrentUserId,
                SLADue          = localTime.AddHours(2),
                //TechnicianId = WebSecurity.CurrentUserId, - assign it to nothing since the dispatch is creating this
                WorkOrderStatusId = (int)WorkOrderStatus.Open,
                AssignmentState   = (int)AssignmentState.Unassigned,
                ZoneId            =
                    asset.MeterMaps.FirstOrDefault() != null?asset.MeterMaps.FirstOrDefault().ZoneId : (int?)null
            };

            fmWorkOrder.AssignmentState = (int)AssignmentState.Unassigned;
            //fmWorkOrder.CompletedDate; //not set here, set upon resolution
            // fmWorkOrder.ParkingSpaceId; //not used, dont have to set parkingspace ID
            //fmWorkOrder.ResolutionCode; - nothing on creation, when resolving, these are maintenance codes
            //fmWorkOrder.ResolutionDesc; -  nothing on creation, when resolving, these are maintenance codes
            MaintenanceEntities.FMWorkOrders.Add(fmWorkOrder);
            MaintenanceEntities.SaveChanges();
            return(fmWorkOrder.WorkOrderId);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a work order in the system
        /// </summary>
        /// <param name="activeAlarmResponse"></param>
        /// <param name="areaId"></param>
        /// <param name="currentCustomer"></param>
        /// <param name="customeId"></param>
        /// <param name="asset"></param>
        /// <param name="meterId"></param>
        /// <param name="maintenanceEntities"></param>
        /// <returns></returns>
        private static FMWorkOrder CreateWorkOrder(DataResponseActiveAlarmsActiveAlarm activeAlarmResponse, int areaId,
                                                   PemsCity currentCustomer, int customeId, Meter asset, int meterId,
                                                   MaintenanceEntities maintenanceEntities)
        {
            //we have to check to see if htey asset already has a work order. if it does, use that work order. This includes any open, incomplete or rejected work orders.
            //we add it to any open work order, even if it is assigned ot another technician (in practice this will almost never happen)
            var existingWorkOrder =
                maintenanceEntities.FMWorkOrders.FirstOrDefault(
                    x =>
                    x.MeterId == meterId && x.CustomerId == customeId && x.AreaId == areaId &&
                    (x.WorkOrderStatusId == (int)WorkOrderStatus.Open ||
                     x.WorkOrderStatusId == (int)WorkOrderStatus.Incomplete ||
                     x.WorkOrderStatusId == (int)WorkOrderStatus.Rejected));

            if (existingWorkOrder != null)
            {
                return(existingWorkOrder);
            }


            //we need to crate a new work order
            //create the work order now. commented out properties we ignore upon creation.
            var fmWorkOrder = new FMWorkOrder
            {
                AreaId            = areaId,
                CreateDateTime    = currentCustomer.LocalTime,
                CustomerId        = customeId, //cid
                HighestSeverity   = 0,
                Location          = asset.Location,
                Mechanism         = asset.MeterType,
                MeterGroup        = asset.MeterGroup ?? 1,
                MeterId           = meterId,
                Notes             = string.Empty,
                SLADue            = activeAlarmResponse.SLADue, //this gets reset anyways, jsut set it to
                WorkOrderStatusId = (int)WorkOrderStatus.Open,
                AssignmentState   = (int)AssignmentState.Unassigned,
                ZoneId            =
                    asset.MeterMaps.FirstOrDefault() != null?asset.MeterMaps.FirstOrDefault().ZoneId : (int?)null
            };

            maintenanceEntities.FMWorkOrders.Add(fmWorkOrder);
            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(fmWorkOrder.WorkOrderId);
            return(fmWorkOrder);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Make a work order part based on the db version
        /// </summary>
        /// <param name="dbItem"></param>
        /// <returns></returns>
        protected Technician MakeTechnicianFromWorkOrder(FMWorkOrder workOrder)
        {
            //check for null
            if (workOrder == null)
            {
                return(new Technician());
            }
            //technicina details
            var tech = new Technician();

            tech.TechnicianID = workOrder.TechnicianId ?? -1;

            if (tech.TechnicianID > 0)
            {
                tech = MakeTechnician(tech.TechnicianID);
            }
            return(tech);
        }
Ejemplo n.º 4
0
        protected WorkOrderAsset MakeWorkOrderAsset(FMWorkOrder workOrder, int customerId)
        {
            var assetFactory   = (new AssetFactory(ConnectionStringName));
            var asset          = assetFactory.GetAsset(customerId, workOrder.AreaId, workOrder.MeterId);
            var workOrderAsset = new WorkOrderAsset
            {
                AssetId = workOrder.MeterId,
                //subtype - call asset factory and pass in mechanismid and customer id to the GetMechanismMasterCustomerDescription - will return the customer specific, or default to the desc of hte mechanism
                AssetSubType    = assetFactory.GetMechanismMasterCustomerDescription(customerId, workOrder.Mechanism),
                AssetType       = assetFactory.GetAssetTypeDescription(workOrder.MeterGroup, customerId),
                AssetAreaName   = assetFactory.GetAssetAreaName(customerId, workOrder.AreaId, workOrder.MeterId),
                AssetName       = asset.MeterName,
                AreaId          = asset.AreaID,
                AssetLastPMDate = asset.LastPreventativeMaintenance
            };

            return(workOrderAsset);
        }