Beispiel #1
0
        //todo - GTC - datakey history - finish this based on another factory example (gateway)
        /// <summary>
        ///  Description: This Method will retrive histtry summary
        ///   ModifiedBy: Santhosh  (26/June/2014 - 04/July/2014)
        /// </summary>
        /// <param name="request"></param>
        /// <param name="total"></param>
        /// <param name="customerId"></param>
        /// <param name="areaId"></param>
        /// <param name="assetId"></param>
        /// <param name="startDateTicks"></param>
        /// <param name="endDateTicks"></param>
        /// <returns></returns>
        public List <DataKeyViewModel> GetHistory([DataSourceRequest] DataSourceRequest request, out int total, int customerId, int areaId, Int64 assetId, long startDateTicks, long endDateTicks)
        {
            DateTime startDate;
            DateTime endDate;

            IQueryable <DataKeyAudit> query = null;

            if (startDateTicks > 0 && endDateTicks > 0)
            {
                startDate = (new DateTime(startDateTicks, DateTimeKind.Utc)).ToLocalTime();
                endDate   = (new DateTime(endDateTicks, DateTimeKind.Utc)).ToLocalTime();
                query     = PemsEntities.DataKeyAudits.Where(m => m.CustomerID == customerId && m.DataKeyId == assetId &&
                                                             m.UpdateDateTime >= startDate && m.UpdateDateTime <= endDate).OrderBy(m => m.UpdateDateTime);
            }
            else if (startDateTicks > 0)
            {
                startDate = (new DateTime(startDateTicks, DateTimeKind.Utc)).ToLocalTime();
                query     = PemsEntities.DataKeyAudits.Where(m => m.CustomerID == customerId && m.DataKeyId == assetId &&
                                                             m.UpdateDateTime >= startDate).OrderBy(m => m.UpdateDateTime);
            }
            else if (endDateTicks > 0)
            {
                endDate = (new DateTime(endDateTicks, DateTimeKind.Utc)).ToLocalTime();
                query   = PemsEntities.DataKeyAudits.Where(m => m.CustomerID == customerId && m.DataKeyId == assetId &&
                                                           m.UpdateDateTime <= endDate).OrderBy(m => m.UpdateDateTime);
            }
            else
            {
                query = PemsEntities.DataKeyAudits.Where(m => m.CustomerID == customerId && m.DataKeyId == assetId).OrderBy(m => m.UpdateDateTime);
            }



            // Get the DataKeyViewModel for each audit record.
            var list = new List <DataKeyViewModel>();

            // Get present data
            var presentModel = GetViewModel(customerId, (int)assetId);

            presentModel.RecordDate = Now;
            list.Add(presentModel);

            // Get historical data view models
            DataKeyViewModel previousModel = null;

            foreach (var dataKeyItem in query)
            {
                var activeModel = CreateHistoricViewModel(dataKeyItem);
                list.Add(activeModel);
                if (previousModel != null)
                {
                    previousModel.RecordSuperceededDate = activeModel.RecordDate;
                }
                previousModel = activeModel;
            }

            // Now filter, sort and page.
            var items = list.AsQueryable();

            //items = items.ApplyFiltering(request.Filters);
            total = items.Count();
            //items = items.ApplySorting(request.Groups, request.Sorts);
            //items = items.ApplyPaging(request.Page, request.PageSize);
            return(items.ToList());
        }
Beispiel #2
0
        /// <summary>
        ///  Description: This Method will create history summary madel  for particular audit
        ///   ModifiedBy: Santhosh  (26/June/2014 - 04/July/2014)
        /// </summary>
        /// <param name="auditModel"></param>
        /// <returns></returns>

        private DataKeyViewModel CreateHistoricViewModel(DataKeyAudit auditModel)
        {
            var model = new DataKeyViewModel()
            {
                CustomerId = auditModel.CustomerID ?? 0,
                AreaId     = (int)AssetAreaId.DataKey,
                AssetId    = auditModel.DataKeyId ?? 0,
            };


            var dataKey = PemsEntities.DataKeys.FirstOrDefault(m => m.CustomerID == model.CustomerId && m.DataKeyId == auditModel.DataKeyId);

            if (dataKey != null)
            {
                //get the meter map, should have this - test for the meter with the correct group
                var meterMap = dataKey.MeterMaps.FirstOrDefault(x => x.Meter != null && x.Meter.MeterGroup == (int)MeterGroups.Datakey && x.DataKeyId == dataKey.DataKeyId);
                if (meterMap != null)
                {
                    //now go get the meter
                    var meter = meterMap.Meter;
                    model.GlobalId = meter.GlobalMeterId.ToString();

                    model.DataKeyIdNumber = meterMap.DataKeyId;

                    model.Type         = PemsEntities.MeterGroups.FirstOrDefault(x => x.MeterGroupId == (int)MeterGroups.Datakey).MeterGroupDesc;
                    model.TypeId       = (int)MeterGroups.Datakey;
                    model.AssetModel   = GetMechanismDescription(model.CustomerId, dataKey.MechType ?? -1);
                    model.AssetModelId = dataKey.DataKeyTypeId;
                    model.Name         = "todo";//todo GTC:datakey - set asset name here for datakey when the db script is added

                    var area = PemsEntities.Areas.FirstOrDefault(m => m.AreaID == meterMap.AreaId2 && m.CustomerID == model.CustomerId);
                    model.Area             = area == null ? "" : area.AreaName;
                    model.AreaId2          = area == null ? -1 : area.AreaID;
                    model.Zone             = meterMap.Zone == null ? "" : meterMap.Zone.ZoneName ?? "";
                    model.ZoneId           = meterMap.Zone == null ? -1 : meterMap.Zone.ZoneId;
                    model.Suburb           = meterMap.CustomGroup11 == null ? " " : meterMap.CustomGroup11.DisplayName;
                    model.MaintenanceRoute = meterMap.MaintRouteId == null ? "-" : meterMap.MaintRoute.DisplayName ?? "-";

                    // Lat/Long
                    model.Latitude  = meter.Latitude ?? 0.0;
                    model.Longitude = meter.Longitude ?? 0.0;

                    model.LastPrevMaint      = meter.LastPreventativeMaintenance.HasValue ? meter.LastPreventativeMaintenance.Value.ToShortDateString() : "";
                    model.NextPrevMaint      = meter.NextPreventativeMaintenance.HasValue ? meter.NextPreventativeMaintenance.Value.ToShortDateString() : "";
                    model.InstallationDate   = meter.InstallDate.HasValue ? meter.InstallDate.Value : (DateTime?)null;
                    model.WarrantyExpiration = meter.WarrantyExpiration.HasValue ? meter.WarrantyExpiration.Value : (DateTime?)null;


                    // Operational status of meter (datakey).
                    DateTime?opStatusDatetime;
                    int?     statusId;
                    model.Status     = GetOperationalStatus(auditModel.DataKeyId ?? 0, out opStatusDatetime, out statusId);
                    model.StatusDate = opStatusDatetime;
                    model.StatusId   = statusId ?? 0;
                    // See if item has pending changes.
                    model.HasPendingChanges = (new PendingFactory(ConnectionStringName, Now)).Pending(model);

                    // Is asset active?
                    model.State = (AssetStateType)(meter.MeterState ?? 0);

                    // Get the full-spell change reason.
                    model.LastUpdatedReason        = (AssetPendingReasonType)(auditModel.AssetPendingReasonId ?? 0);
                    model.LastUpdatedReasonDisplay = PemsEntities.AssetPendingReasons.FirstOrDefault(m => m.AssetPendingReasonId == (int)model.LastUpdatedReason).AssetPendingReasonDesc;


                    //custom datakey properties
                    model.Street = model.Location = GetMechanismLocation(model.CustomerId, dataKey.DataKeyId);

                    // Get last update by information
                    CreateAndLastUpdate(model);

                    // Record date
                    model.RecordDate = auditModel.UpdateDateTime;

                    // Audit record id
                    model.AuditId = auditModel.DataKeyAuditId;
                }
            }


            return(model);
        }
Beispiel #3
0
 public int Clone(DataKeyViewModel model)
 {
     return(Clone(model.CustomerId, model.AssetId));
 }