Beispiel #1
0
        /// <summary>
        /// Refreshes any lists in the <see cref="CashboxEditModel"/> instance.  This is used
        /// where a model has been submitted from a web page but the contents of the dropdown lists were not passed back.
        /// </summary>
        /// <param name="editModel">The instance of the <see cref="CashboxEditModel"/> to refresh</param>
        public void RefreshEditModel(CashboxEditModel editModel)
        {
            // Get sensor models.
            GetAssetModelList(editModel, (int)MeterGroups.Cashbox);

            // Cashbox location
            editModel.Location = (from cbl in PemsEntities.CashBoxLocationTypes
                                  select new SelectListItemWrapper()
            {
                Selected = cbl.CashBoxLocationTypeId == editModel.LocationId,
                Text = cbl.CashBoxLocationTypeDesc,
                ValueInt = cbl.CashBoxLocationTypeId
            }).ToList();
            editModel.Location.Insert(0, new SelectListItemWrapper()
            {
                Selected = editModel.LocationId == -1,
                Text     = "",
                Value    = "-1"
            });

            //// Operational status of meter.
            //GetOperationalStatusList(editModel, editModel.Status.StatusId);

            // Get state list
            GetAssetStateList(editModel);
        }
Beispiel #2
0
        /// <summary>
        /// Saves the updates of an instance of <see cref="CashboxEditModel"/> to the [AssetPending] table.
        /// </summary>
        /// <param name="model">Instance of a <see cref="CashboxEditModel"/> with updates</param>
        public void SetEditModel(CashboxEditModel model)
        {
            // Note:  At this time all changes to the gateway are written to the [AssetPending] table.

            var otherModel = GetEditModel(model.CustomerId, (int)model.AssetId);

            // Write changes to [AssetPending] table.
            (new PendingFactory(ConnectionStringName, Now)).Save(model, otherModel);
        }
Beispiel #3
0
        public static MvcHtmlString AssetCashBoxCreatedStatusMsg(this HtmlHelper htmlHelper, ModelStateDictionary modelState, CashboxEditModel 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 CashBox " + model.AssetId + " for City " + currCity + " Successfully Created.");
                }
                else
                {
                    sb.Append("CashBox " + 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()));
        }
Beispiel #4
0
 /// <summary>
 /// Creates a clone (copy) of the <see cref="CashBox"/> refrenced by <paramref name="model"/>.  This cloned
 /// <see cref="CashBox"/> is written to the [CashBox] table and the [AssetPending] table.
 /// </summary>
 /// <param name="model">An instance of <see cref="CashboxViewModel"/> referencinf cashbox to be cloned</param>
 /// <returns>Integer representing the new cashbox id. <see cref="CashBox.CashBoxID"/></returns>
 public int Clone(CashboxEditModel model)
 {
     return(Clone(model.CustomerId, model.AreaId, model.AssetId));
 }
Beispiel #5
0
        /// <summary>
        /// Returns an instance of <see cref="CashboxEditModel"/> reflecting the present and any pending state
        /// and settings of a <see cref="CashBox"/> for customer id of <paramref name="customerId"/>
        /// and a cashbox id of <paramref name="cashboxId"/>. This model is used for edit page.
        /// </summary>
        /// <param name="customerId">The customer id</param>
        /// <param name="cashboxId">The cashbox id</param>
        /// <returns>An instance of <see cref="CashboxEditModel"/></returns>
        public CashboxEditModel GetEditModel(int customerId, int cashboxId)
        {
            var cashbox = PemsEntities.CashBoxes.FirstOrDefault(m => m.CustomerID == customerId && m.CashBoxSeq == cashboxId);

            var model = new CashboxEditModel
            {
                CustomerId = customerId,
                AreaId     = (int)AssetAreaId.Cashbox,
                AssetId    = cashboxId
            };


            // First build the edit model from the existing cashbox.
            #region Build model from a cashbox

            model.GlobalId = cashbox.CashBoxID.ToString();

            // Cashbox Type
            model.Type   = cashbox.MeterGroup == null ? CashboxViewModel.DefaultType : cashbox.MeterGroup.MeterGroupDesc ?? CashboxViewModel.DefaultType;
            model.TypeId = (MeterGroups)(cashbox.CashBoxType ?? (int)MeterGroups.Cashbox);

            // Get sensor models.
            model.AssetModelId = cashbox.CashBoxModel ?? -1;
            GetAssetModelList(model, (int)MeterGroups.Cashbox);

            // Get meter name.
            model.Name = cashbox.CashBoxName ?? "";

            // Cashbox location
            model.LocationId = cashbox.CashBoxLocationTypeId ?? -1;

            // Preventative maintenance dates
            model.LastPrevMaint = cashbox.LastPreventativeMaintenance.HasValue ? cashbox.LastPreventativeMaintenance.Value.ToShortDateString() : "";
            model.NextPrevMaint = cashbox.NextPreventativeMaintenance.HasValue ? cashbox.NextPreventativeMaintenance.Value : (DateTime?)null;

            // Warantry expiration
            model.WarrantyExpiration = cashbox.WarrantyExpiration.HasValue ? cashbox.WarrantyExpiration.Value : (DateTime?)null;

            // Operational status of meter.
            GetOperationalStatusDetails(model, cashbox.OperationalStatus ?? 0, cashbox.OperationalStatusTime.HasValue ? cashbox.OperationalStatusTime.Value : DateTime.Now);
//            GetOperationalStatusList(model, cashbox.OperationalStatus ?? -1);

            // Is asset active?
            model.StateId = cashbox.CashBoxState;

            #endregion


            // If there is an asset pending record then update edit model with associated values.
            var assetPending = PemsEntities.AssetPendings.FirstOrDefault(m => m.CustomerId == model.CustomerId && m.AreaId == model.AreaId && m.MeterMapGatewayId == cashbox.CashBoxID);

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

                // Get cashbox models.
                model.AssetModelId = assetPending.AssetModel ?? model.AssetModelId;

                // Get cashbox name.
                model.Name = string.IsNullOrWhiteSpace(assetPending.AssetName) ? model.Name : assetPending.AssetName;

                // Get location
                model.LocationId = assetPending.CashboxLocationId ?? model.LocationId;

                // Preventative maintenance dates
                model.LastPrevMaint = assetPending.LastPreventativeMaintenance.HasValue ? assetPending.LastPreventativeMaintenance.Value.ToShortDateString() : model.LastPrevMaint;
                model.NextPrevMaint = assetPending.NextPreventativeMaintenance ?? model.NextPrevMaint;

                // Warantry expiration
                model.WarrantyExpiration = assetPending.WarrantyExpiration ?? model.WarrantyExpiration;

                // Operational status of cashbox.
                if (assetPending.OperationalStatus != null)
                {
                    GetOperationalStatusDetails(model, assetPending.OperationalStatus.Value, assetPending.OperationalStatusTime.HasValue ? assetPending.OperationalStatusTime.Value : DateTime.Now);
                }
//                GetOperationalStatusList(model, (int)(assetPending.OperationalStatus ?? cashbox.OperationalStatus));

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

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

                #endregion
            }

            // Possible cashbox locations
            model.Location = (from cbl in PemsEntities.CashBoxLocationTypes
                              select new SelectListItemWrapper()
            {
                Selected = cbl.CashBoxLocationTypeId == model.LocationId,
                Text = cbl.CashBoxLocationTypeDesc,
                ValueInt = cbl.CashBoxLocationTypeId
            }).ToList();
            model.Location.Insert(0, new SelectListItemWrapper()
            {
                Selected = model.LocationId == -1,
                Text     = "",
                Value    = "-1"
            });


            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);
        }