/// <summary>
        /// Get a queryable list of cashbox summaries (<see cref="IQueryable{AssetListModel}"/>) for
        /// customer id of <paramref name="customerId"/>
        /// </summary>
        /// <param name="customerId">The customer id</param>
        /// <param name="gridType">The type of grid (<see cref="AssetListGridType"/>) that will be using the data</param>
        /// <returns>An instance of <see cref="IQueryable{AssetListModel}"/></returns>
        public IQueryable <AssetListModel> GetSummaryModels(int customerId, AssetListGridType gridType)
        {
            //dont return anything if this is for occupancy
            if (gridType != AssetListGridType.Occupancy)
            {
                //NOTE: we are intentionally leaving some fields blank - per the spec.
                IQueryable <AssetListModel> items = PemsEntities.CashBoxes.Where(m => m.CustomerID == customerId).Select(
                    item =>
                    new AssetListModel
                {
                    //----------DETAIL LINKS
                    Type       = "Cashbox", //name of the details page (ViewCashbox)
                    AreaId     = (int)AssetAreaId.Cashbox,
                    CustomerId = customerId,

                    //-----------FILTERABLE ITEMS
                    AssetType         = item.MeterGroup == null ? CashboxViewModel.DefaultType : item.MeterGroup.MeterGroupDesc ?? CashboxViewModel.DefaultType,
                    AssetId           = item.CashBoxSeq, //item.CashBoxID,
                    AssetName         = item.CashBoxName,
                    InventoryStatus   = item.CashBoxState == null ? "": item.AssetState.AssetStateDesc,
                    OperationalStatus = item.OperationalStatu == null ? " " : item.OperationalStatu.OperationalStatusDesc,
                    //Latitude
                    //Longitude
                    //AreaId2
                    //ZoneId
                    Suburb       = "",
                    Street       = "",
                    DemandStatus = "",

                    //------------COMMON COLUMNS
                    AssetModel = item.MechanismMaster == null ? " "
                            : PemsEntities.MechanismMasterCustomers.FirstOrDefault(m => m.CustomerId == customerId && m.MechanismId == item.MechanismMaster.MechanismId && m.IsDisplay) == null ? " "
                            : PemsEntities.MechanismMasterCustomers.FirstOrDefault(m => m.CustomerId == customerId && m.MechanismId == item.MechanismMaster.MechanismId && m.IsDisplay).MechanismDesc,

                    //------------SUMMARY GRID
                    //SpacesCount
                    Area = "",
                    Zone = "",

                    //---------------CONFIGURATION GRID
                    DateInstalled = item.InstallDate,
                    //ConfigurationId
                    //ConfigCreationDate
                    //ConfigScheduleDate
                    //ConfigActivationDate
                    //MpvVersion
                    //SoftwareVersion
                    //FirmwareVersion

                    //-------------OCCUPANCY GRID - only valid for spaces
                    //MeterName
                    //SensorName
                    OperationalStatusDate = item.OperationalStatusTime,
                    //OccupancyStatus
                    //OccupancyStatusDate
                    //NonComplianceStatus
                    //NonComplianceStatusDate

                    //------------FUNCTIONAL STATUS GRID
                    //AlarmClass
                    //AlarmCode
                    //AlarmTimeOfOccurance
                    //AlarmRepairTargetTime
                    LocalTime = Now
                });
                return(items);
            }
            return(new List <AssetListModel>().AsQueryable());
        }
Exemple #2
0
        /// <summary>
        /// Get a queryable list of datakey summaries (<see cref="IQueryable{AssetListModel}"/>) for
        /// customer id of <paramref name="customerId"/>
        /// </summary>
        /// <param name="customerId">The customer id</param>
        /// <param name="gridType">The type of grid (<see cref="AssetListGridType"/>) that will be using the data</param>
        /// <returns>An instance of <see cref="IQueryable{AssetListModel}"/></returns>
        public IQueryable <AssetListModel> GetSummaryModels(int customerId, AssetListGridType gridType)
        {
            var items = from datakey in PemsEntities.DataKeys
                        where datakey.CustomerID == customerId
                        join meterMap in PemsEntities.MeterMaps on
                        new { DataKeyId = datakey.DataKeyId, CustomerId = datakey.CustomerID } equals
            new { DataKeyId = meterMap.DataKeyId.Value, CustomerId = meterMap.Customerid } into l1
            from mm in l1.DefaultIfEmpty()
            let aa = mm.Meter.ActiveAlarms.OrderByDescending(x => x.TimeOfOccurrance).FirstOrDefault()
                     join profMeters in PemsEntities.VersionProfileMeters on
                     new { MeterId = mm.MeterId, AreaId = mm.Areaid, CustomerId = mm.Customerid } equals
            new { MeterId = profMeters.MeterId.Value, AreaId = profMeters.AreaId.Value, CustomerId = profMeters.CustomerId } into l4
            from vpn in l4.DefaultIfEmpty()
            select
            new AssetListModel
            {
                //----------DETAIL LINKS
                Type       = "DataKey",           //name of the details page (ViewDataKey)
                AreaId     = (int)AssetAreaId.DataKey,
                CustomerId = customerId,

                //-----------FILTERABLE ITEMS
                AssetType       = PemsEntities.MeterGroups.FirstOrDefault(x => x.MeterGroupId == (int)MeterGroups.Datakey).MeterGroupDesc,
                AssetId         = datakey.DataKeyIdNumber ?? mm.DataKeyId.Value,
                AssetName       = mm.Meter.MeterName,
                InventoryStatus = datakey.MeterMaps.FirstOrDefault(x => x.Meter != null && x.Meter.MeterGroup != (int)MeterGroups.Datakey) == null ? " "
                                 : datakey.MeterMaps.FirstOrDefault(x => x.Meter != null && x.Meter.MeterGroup != (int)MeterGroups.Datakey).Meter.MeterState == null ? " "
                                 : datakey.MeterMaps.FirstOrDefault(x => x.Meter != null && x.Meter.MeterGroup != (int)MeterGroups.Datakey).Meter.AssetState.AssetStateDesc,

                //have to make sure we get the op status of the meter that this datakey is installed in, and NOT the "Meter" table entry for this datakey
                OperationalStatus = datakey.MeterMaps.FirstOrDefault(x => x.Meter != null && x.Meter.MeterGroup != (int)MeterGroups.Datakey) == null ? " "
                                 : datakey.MeterMaps.FirstOrDefault(x => x.Meter != null && x.Meter.MeterGroup != (int)MeterGroups.Datakey).Meter.OperationalStatu == null ? " "
                                 : datakey.MeterMaps.FirstOrDefault(x => x.Meter != null && x.Meter.MeterGroup != (int)MeterGroups.Datakey).Meter.OperationalStatu.OperationalStatusDesc,
                Latitude  = mm.Meter.Latitude,
                Longitude = mm.Meter.Longitude,
                AreaId2   = mm.AreaId2,
                ZoneId    = mm.ZoneId,
                Suburb    = PemsEntities.CustomGroup1.FirstOrDefault(x => x.CustomGroupId == mm.CustomGroup1 && x.CustomerId == customerId) == null ? " "
                                    : PemsEntities.CustomGroup1.FirstOrDefault(x => x.CustomGroupId == mm.CustomGroup1 && x.CustomerId == customerId).DisplayName,
                Street       = mm.Meter.Location ?? " ",
                DemandStatus = PemsEntities.DemandZones.FirstOrDefault(x => x.DemandZoneId == mm.Meter.DemandZone) == null ? "" : PemsEntities.DemandZones.FirstOrDefault(x => x.DemandZoneId == mm.Meter.DemandZone).DemandZoneDesc,

                //------------COMMON COLUMNS
                AssetModel = datakey.DataKeyDesc,

                //------------SUMMARY GRID
                //SpacesCount = PemsEntities.SensorMappings.Count(x => x.CustomerID == customerId && x.GatewayID == g.GateWayID),
                Area = PemsEntities.Areas.FirstOrDefault(x => x.CustomerID == customerId && x.AreaID == mm.AreaId2) == null ? ""
                                    : PemsEntities.Areas.FirstOrDefault(x => x.CustomerID == customerId && x.AreaID == mm.AreaId2).AreaName,
                Zone = PemsEntities.Zones.FirstOrDefault(x => x.ZoneId == mm.ZoneId && x.customerID == customerId) == null ? ""
                                    : PemsEntities.Zones.FirstOrDefault(x => x.ZoneId == mm.ZoneId && x.customerID == customerId).ZoneName,

                //---------------CONFIGURATION GRID
                //DateInstalled
                // ConfigurationId
                //ConfigCreationDate
                //ConfigScheduleDate
                //ConfigActivationDate
                //MpvVersion
                //SoftwareVersion
                //FirmwareVersion

                //-------------OCCUPANCY GRID - only valid for spaces
                //MeterName
                //SensorName
                // OperationalStatusDate
                //OccupancyStatus
                //OccupancyStatusDate
                //NonComplianceStatus
                //NonComplianceStatusDate

                //------------FUNCTIONAL STATUS GRID
                AlarmClass            = aa.EventCode1.AlarmTier1.TierDesc,
                AlarmCode             = aa == null ? "" : aa.EventCode1 == null ? "" : aa.EventCode1.EventDescVerbose,
                AlarmTimeOfOccurance  = aa == null ? (DateTime?)null : aa.TimeOfOccurrance,
                AlarmRepairTargetTime = aa == null ? (DateTime?)null : aa.SLADue,
                LocalTime             = Now
            };

            return(items);
        }