Exemple #1
0
        public static MvcHtmlString AssetDatakeyCreatedStatusMsg(this HtmlHelper htmlHelper, ModelStateDictionary modelState, DataKeyEditModel model, string currCity, string assetIdStatus)
        {
            var sb = new StringBuilder();

            if (model.Saved)
            {
                sb.Append("<span class=\"").Append("page-validation-error").Append("\">");
                if (assetIdStatus == "New")
                {
                    sb.Append("New DataKey " + model.AssetId + " for City " + currCity + " Successfully Created.");
                }
                else
                {
                    sb.Append("DataKey " + model.AssetId + " for City " + currCity + " Successfully Updated.");
                }
                sb.Append("</span>");
            }
            else
            {
                sb.Append("<span class=\"").Append("page-validation-error").Append("\">");
                sb.Append("");
                sb.Append("</span>");
            }
            return(MvcHtmlString.Create(sb.ToString()));
        }
Exemple #2
0
 public int Clone(DataKeyEditModel model)
 {
     return(Clone(model.CustomerId, model.AssetId));
 }
Exemple #3
0
 public void RefreshEditModel(DataKeyEditModel model)
 {
     GetAssetModelList(model, (int)MeterGroups.Datakey);
     GetAssetStateList(model);
 }
Exemple #4
0
        public void SetEditModel(DataKeyEditModel model)
        {
            var otherModel = GetEditModel(model.CustomerId, (int)model.AssetId);

            (new PendingFactory(ConnectionStringName, Now)).Save(model, otherModel);
        }
Exemple #5
0
        public DataKeyEditModel GetEditModel(int customerId, int dataKeyId)
        {
            var model = new DataKeyEditModel
            {
                CustomerId    = customerId,
                AreaId        = (int)AssetAreaId.DataKey,
                AssetId       = dataKeyId,
                Configuration = new AssetConfigurationModel()
            };

            var dataKey = PemsEntities.DataKeys.FirstOrDefault(m => m.CustomerID == customerId && m.DataKeyIdNumber == 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);
                if (meterMap != null)
                {
                    //now go get the meter
                    var meter = meterMap.Meter;
                    // First build the edit model from the existing
                    model.GlobalId = meter.GlobalMeterId.ToString();

                    model.Type            = PemsEntities.MeterGroups.FirstOrDefault(x => x.MeterGroupId == (int)MeterGroups.Datakey).MeterGroupDesc;
                    model.TypeId          = MeterGroups.Datakey;
                    model.DataKeyIdNumber = dataKeyId;

                    model.AssetModelId = dataKey.DataKeyTypeId;
                    GetAssetModelList(model, (int)MeterGroups.Datakey);
                    model.Name = "todo";//todo gtc set this as the asset name when we get that field added to datakey "Name";

                    // 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 : (DateTime?)null;
                    model.WarrantyExpiration = meter.WarrantyExpiration.HasValue ? meter.WarrantyExpiration.Value : (DateTime?)null;
                    model.InstallationDate   = meter.InstallDate.HasValue ? meter.InstallDate.Value : (DateTime?)null;
                    model.Configuration      = new AssetConfigurationModel
                    {
                        DateInstalled = meter.InstallDate.HasValue ? meter.InstallDate.Value : (DateTime?)null
                    };
                    // Operational status of meter (datakey).
                    DateTime?opStatusDatetime;
                    int?     opStatusId;
                    model.Status     = GetOperationalStatus(dataKeyId, out opStatusDatetime, out opStatusId);
                    model.StatusDate = opStatusDatetime;
                    model.StatusId   = opStatusId ?? 0;
                    //make sure this is using the meter assigned to the datakey and not the meter that represetnts the datakey
                    GetOperationalStatusDetails(model, model.StatusId, model.StatusDate.HasValue ? model.StatusDate.Value : DateTime.Now);

                    // Is asset active?
                    model.StateId = meter.MeterState.GetValueOrDefault();

                    //custom datakey properties
                    model.Street = model.Location = GetDataKeyLocation(customerId, dataKey.DataKeyId);
                }
            }

            // Is asset active?

            #endregion

            // If there is an asset pending record then update edit model with associated values.
            //metermapdatakeyid - todo - update this when the asset pending table
            var assetPending = PemsEntities.AssetPendings.FirstOrDefault(m => m.CustomerId == model.CustomerId && m.AreaId == model.AreaId && m.AssetType == (int)MeterGroups.Datakey && m.MeterId == dataKeyId);

            if (assetPending != null)
            {
                #region Update model from an assetPending

                // Get datakey models.
                model.AssetModelId = assetPending.AssetModel ?? model.AssetModelId;
                // Get name.
                //todo - gtc: datakey - get this working once they add the name ot the datakey table. This may be datakaydesc
                model.Name   = string.IsNullOrWhiteSpace(assetPending.AssetName) ? model.Name : assetPending.AssetName;
                model.Street = model.Location = string.IsNullOrWhiteSpace(assetPending.LocationMeters) ? model.Street : assetPending.LocationMeters;
                // Get Zone, Area and Suburb
                model.AreaListId = assetPending.MeterMapAreaId2 ?? model.AreaListId;
                model.ZoneId     = assetPending.MeterMapZoneId ?? model.ZoneId;
                model.SuburbId   = assetPending.MeterMapSuburbId ?? model.SuburbId;
                // Preventative maintenance dates
                model.LastPrevMaint = assetPending.LastPreventativeMaintenance.HasValue ? assetPending.LastPreventativeMaintenance.Value.ToShortDateString() : model.LastPrevMaint;
                model.NextPrevMaint = assetPending.NextPreventativeMaintenance ?? model.NextPrevMaint;
                // Lat/Long
                model.Latitude  = assetPending.Latitude ?? model.Latitude;
                model.Longitude = assetPending.Longitude ?? model.Longitude;
                // Warantry expiration
                model.WarrantyExpiration = assetPending.WarrantyExpiration ?? model.WarrantyExpiration;
                // Version profile information

                model.Configuration.DateInstalled   = model.InstallationDate = assetPending.DateInstalled ?? (model.Configuration == null ? (DateTime?)null : model.Configuration.DateInstalled);
                model.Configuration.MPVVersion      = assetPending.MPVFirmware ?? (model.Configuration == null ? "" : model.Configuration.MPVVersion);
                model.Configuration.SoftwareVersion = assetPending.AssetSoftwareVersion ?? (model.Configuration == null ? "" : model.Configuration.SoftwareVersion);
                model.Configuration.FirmwareVersion = assetPending.AssetFirmwareVersion ?? (model.Configuration == null ? "" : model.Configuration.FirmwareVersion);
                // Operational status of datakey.
                if (assetPending.OperationalStatus != null)
                {
                    GetOperationalStatusDetails(model, assetPending.OperationalStatus.Value, assetPending.OperationalStatusTime.HasValue ? assetPending.OperationalStatusTime.Value : DateTime.Now);
                }

                // Asset state is pending
                model.StateId = (int)AssetStateType.Pending;

                // Activation Date
                model.ActivationDate = assetPending.RecordMigrationDateTime;

                #endregion
            }

            GetAssetStateList(model);

            // Initialize ActivationDate if needed and set to midnight.
            if (!model.ActivationDate.HasValue)
            {
                model.ActivationDate = Now;
            }
            model.ActivationDate = SetToMidnight(model.ActivationDate.Value);

            return(model);
        }