Esempio n. 1
0
        /// <summary>
        /// Adds a new version (name) for a particular <paramref name="fileType"/>, <paramref name="meterGroup"/>,
        /// and <paramref name="versionGroup"/>.
        /// </summary>
        /// <param name="name">Version name to add</param>
        /// <param name="fileType">File type id</param>
        /// <param name="meterGroup">Meter Group id <see cref="MeterGroups"/></param>
        /// <param name="versionGroup">Version group id</param>
        public void AddVersion(string name, int fileType, int meterGroup, int versionGroup)
        {
            // Get/create a row in [FDFileTypeMeterGroup]
            var fdftmg = PemsEntities.FDFileTypeMeterGroups.FirstOrDefault(m => m.FileType == fileType &&
                                                                           (meterGroup == -1 ? m.MeterGroup == null : m.MeterGroup == meterGroup) &&
                                                                           (versionGroup == -1 ? m.VersionGroup == null : m.VersionGroup == versionGroup));

            if (fdftmg == null)
            {
                fdftmg = new FDFileTypeMeterGroup()
                {
                    FileType     = fileType,
                    MeterGroup   = meterGroup == -1 ? null : (int?)meterGroup,
                    VersionGroup = versionGroup == -1 ? null : (int?)versionGroup
                };
                PemsEntities.FDFileTypeMeterGroups.Add(fdftmg);
                PemsEntities.SaveChanges();
            }

            // Add a row in [AssetVersionMaster]
            var avm = new AssetVersionMaster()
            {
                FDFileTypeMeterGroupID = fdftmg.FDFileTypeMeterGroupID,
                VersionName            = name.Trim(),
                CreateDate             = DateTime.Now
            };

            PemsEntities.AssetVersionMasters.Add(avm);
            PemsEntities.SaveChanges();
        }
Esempio n. 2
0
        public PropertyGroupItem GetPropertyGroupItem(int customerId, string propertyGroupName, string itemName)
        {
            var propertyGroup    = GetCustomerPropertyGroup(customerId, propertyGroupName);
            var customerProperty = PemsEntities.CustomerProperties.FirstOrDefault(m => m.CustomerPropertyGroupId == propertyGroup.CustomerPropertyGroupId &&
                                                                                  m.PropertyDesc.Equals(itemName));

            if (customerProperty == null)
            {
                // Need to get max SortOrder of existing items.
                int nextSortOrder = 0;
                var propertySet   = PemsEntities.CustomerProperties.Where(cp => propertyGroup.CustomerPropertyGroupId == cp.CustomerPropertyGroupId);
                if (propertySet.Any())
                {
                    nextSortOrder = propertySet.Max(m => m.SortOrder) + 1;
                }

                customerProperty = new CustomerProperty()
                {
                    CustomerPropertyGroupId = propertyGroup.CustomerPropertyGroupId,
                    CustomerID   = customerId,
                    PropertyDesc = itemName,
                    SortOrder    = nextSortOrder
                };
                PemsEntities.CustomerProperties.Add(customerProperty);
                PemsEntities.SaveChanges();
            }

            return(new PropertyGroupItem()
            {
                Id = customerProperty.CustomerPropertyId,
                Value = customerProperty.PropertyDesc,
                SortOrder = customerProperty.SortOrder
            });
        }
Esempio n. 3
0
        public CashBox Create(int customerId, AssetTypeModel.EnterMode enterMode, int cashBoxID)
        {
            // Create new cashbox
            int     areaId  = (int)AssetAreaId.Cashbox;
            CashBox cashbox = new CashBox()
            {
                //CashBoxID = NextCashBoxId(customerId),
                //  CashBoxID = cashBoxID,
                CustomerID            = customerId,
                CashBoxName           = "",
                CashBoxSeq            = cashBoxID,
                CashBoxState          = (int)AssetStateType.Pending,
                CashBoxType           = (int)MeterGroups.Cashbox,
                OperationalStatus     = (int)OperationalStatusType.Inactive,
                OperationalStatusTime = DateTime.Now,
                CashBoxLocationTypeId = (int)Duncan.PEMS.Entities.Enumerations.CashBoxLocationType.Inventory
            };

            PemsEntities.CashBoxes.Add(cashbox);
            PemsEntities.SaveChanges();

            // Create audit record.
            Audit(cashbox);

            return(cashbox);
        }
Esempio n. 4
0
        /// <summary>
        /// Description:This method will update the seleted vendor's customer and duncan property shown in editpaybycell by altering 'ValueText' of RipnetProperties table
        /// Modified:Prita()
        /// </summary>
        /// <param name="VID"></param>
        /// <param name="VName"></param>
        /// <param name="CustID"></param>
        /// <param name="DuncanGriddata"></param>
        /// <param name="CustGriddata"></param>
        public void UpdateVendorDetails(int VID, string VName, int CustID, DuncanPropertyModel[] DuncanGriddata, CustomerPropertyModel[] CustGriddata)
        {
            foreach (var item in DuncanGriddata)
            {
                var KeyString = "paybycell.dp." + CustID + "." + VID + ".";
                if (item.KeyText != item.KeyTextOld || item.ValueText != item.ValueTextOld)
                {
                    var stud = (from s in PemsEntities.RipnetProperties
                                where (s.KeyText == KeyString + item.KeyTextOld) || (s.ValueText == item.ValueTextOld)
                                select s).FirstOrDefault();

                    // stud.KeyText = KeyString + item.KeyText;
                    stud.ValueText = item.ValueText;
                    PemsEntities.SaveChanges();
                }
            }

            foreach (var item in CustGriddata)
            {
                var KeyString = "paybycell.cp." + CustID + "." + VID + ".";
                if (item.KeyText != item.KeyTextOld || item.ValueText != item.ValueTextOld)
                {
                    var stud = (from s in PemsEntities.RipnetProperties
                                where (s.KeyText == KeyString + item.KeyTextOld) || (s.ValueText == item.ValueTextOld)
                                select s).FirstOrDefault();

                    //stud.KeyText = KeyString + item.KeyText;
                    stud.ValueText = item.ValueText;
                    PemsEntities.SaveChanges();
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Adds an audit record to [EventCodesAudit] table.
        /// </summary>
        /// <param name="itemToAudit"><see cref="EventCode"/> instance to add to audit table.</param>
        public void Audit(EventCode itemToAudit)
        {
            // Get out if nothing to audit.
            if (itemToAudit == null)
            {
                return;
            }

            EventCodesAudit audit = new EventCodesAudit();

            audit.CustomerID       = itemToAudit.CustomerID;
            audit.EventSource      = itemToAudit.EventSource;
            audit.EventCode        = itemToAudit.EventCode1;
            audit.AlarmTier        = itemToAudit.AlarmTier;
            audit.EventDescAbbrev  = itemToAudit.EventDescAbbrev;
            audit.EventDescVerbose = itemToAudit.EventDescVerbose;
            audit.SLAMinutes       = itemToAudit.SLAMinutes;
            audit.IsAlarm          = itemToAudit.IsAlarm;
            audit.EventType        = itemToAudit.EventType;
            audit.ApplySLA         = itemToAudit.ApplySLA;
            audit.EventCategory    = itemToAudit.EventCategory;

            audit.UserId          = WebSecurity.CurrentUserId;
            audit.UpdatedDateTime = DateTime.Now;

            PemsEntities.EventCodesAudits.Add(audit);
            PemsEntities.SaveChanges();
        }
Esempio n. 6
0
        public string AddAutoAlarm(int CustomerID, string LowBattAlarmCodeMinor,
                                   string LowBattAlarmCodeMajor, string LowBattEnabledMeters,
                                   string NoCommAlarmCode, string NoCommEnabledMeters)
        {
            try
            {
                LowBattAlarmCodeMinor = LowBattAlarmCodeMinor.Substring(0, LowBattAlarmCodeMinor.IndexOf('('));
                LowBattAlarmCodeMajor = LowBattAlarmCodeMajor.Substring(0, LowBattAlarmCodeMajor.IndexOf('('));
                NoCommAlarmCode       = NoCommAlarmCode.Substring(0, NoCommAlarmCode.IndexOf('('));

                var text    = "Databus.AutoAlarm.LowBatt.AlarmCodeMinor." + CustomerID;
                var ripcust = PemsEntities.RipnetProperties.FirstOrDefault(c => c.KeyText.Contains(text));
                if (ripcust != null)
                {
                    return("0");
                }

                RipnetProperty DuncanProp = new RipnetProperty();

                DuncanProp.KeyText   = "Databus.AutoAlarm.LowBatt.AlarmCodeMinor." + CustomerID;
                DuncanProp.ValueText = PemsEntities.EventCodes.FirstOrDefault(e => e.EventDescVerbose == LowBattAlarmCodeMinor).EventCode1.ToString();
                PemsEntities.RipnetProperties.Add(DuncanProp);
                PemsEntities.SaveChanges();

                RipnetProperty DuncanProp1 = new RipnetProperty();
                DuncanProp1.KeyText   = "Databus.AutoAlarm.LowBatt.AlarmCodeMajor." + CustomerID;
                DuncanProp1.ValueText = PemsEntities.EventCodes.FirstOrDefault(e => e.EventDescVerbose == LowBattAlarmCodeMajor).EventCode1.ToString();
                PemsEntities.RipnetProperties.Add(DuncanProp1);
                PemsEntities.SaveChanges();

                RipnetProperty DuncanProp2 = new RipnetProperty();
                DuncanProp2.KeyText   = "Databus.AutoAlarm.LowBatt.EnabledMeters." + CustomerID;
                DuncanProp2.ValueText = LowBattEnabledMeters;
                PemsEntities.RipnetProperties.Add(DuncanProp2);
                PemsEntities.SaveChanges();

                RipnetProperty DuncanProp3 = new RipnetProperty();
                DuncanProp3.KeyText   = "Databus.AutoAlarm.NoComm.AlarmCode." + CustomerID;
                DuncanProp3.ValueText = PemsEntities.EventCodes.FirstOrDefault(e => e.EventDescVerbose == NoCommAlarmCode).EventCode1.ToString();
                PemsEntities.RipnetProperties.Add(DuncanProp3);
                PemsEntities.SaveChanges();

                RipnetProperty DuncanProp4 = new RipnetProperty();
                DuncanProp4.KeyText   = "Databus.AutoAlarm.NoComm.EnabledMeters." + CustomerID;
                DuncanProp4.ValueText = NoCommEnabledMeters;
                PemsEntities.RipnetProperties.Add(DuncanProp4);
                PemsEntities.SaveChanges();


                return("1");
            }
            catch (Exception ex)
            {
                return("-1");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Enable or disable a customer
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="customerDetailId"></param>
        /// <param name="enabled"></param>
        public void Enable(int customerId, int customerDetailId, bool enabled)
        {
            // Get the CustomerDetail
            var customerDetail = PemsEntities.CustomerDetails.FirstOrDefault(m => m.ID == customerDetailId);

            if (customerDetail != null)
            {
                customerDetail.IsDisplay = enabled;
                PemsEntities.SaveChanges();
            }
        }
Esempio n. 8
0
        /// <summary>
        ///Description:This method will set the seleted vendor as 'no more in use' by altering data in 'DEPRECATE' of PayByCellVendors table
        ///Modified:Prita()
        /// </summary>
        /// <param name="VID"></param>
        public void DepricateVendorRecords(int VID)
        {
            {
                var stud = (from s in PemsEntities.PayByCellVendors
                            where (s.VendorID == VID)
                            select s).FirstOrDefault();

                //stud.KeyText = KeyString + item.KeyText;
                stud.DEPRECATE = false;
                PemsEntities.SaveChanges();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Updates a discount scheme users status
        /// </summary>
        private void UpdateStatus(int userId, string notes, int statusID)
        {
            //ge the user acount
            var user = PemsEntities.Users.FirstOrDefault(x => x.UserID == userId);

            if (user != null)
            {
                //just change status to 0 (terminated)
                user.AccountStatus = statusID;
                user.UserNote      = notes;
                PemsEntities.SaveChanges();
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the property group for a customer
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="propertyGroupName"></param>
        /// <returns></returns>
        private CustomerPropertyGroup GetCustomerPropertyGroup(int customerId, string propertyGroupName)
        {
            CustomerPropertyGroup propertyGroup = PemsEntities.CustomerPropertyGroups
                                                  .FirstOrDefault(m => m.PropertyGroupDesc.Equals(propertyGroupName) && m.CustomerID == customerId);

            if (propertyGroup == null)
            {
                propertyGroup = new CustomerPropertyGroup()
                {
                    CustomerID        = customerId,
                    PropertyGroupDesc = propertyGroupName
                };
                PemsEntities.CustomerPropertyGroups.Add(propertyGroup);
                PemsEntities.SaveChanges();
            }

            return(propertyGroup);
        }
Esempio n. 11
0
        /// <summary>
        /// Sets a property for a specific customer
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="propertyGroupName"></param>
        /// <param name="propertyValue"></param>
        public void Set(int customerId, string propertyGroupName, bool propertyValue)
        {
            var propertyGroup = GetCustomerPropertyGroup(customerId, propertyGroupName);

            var customerProperty = PemsEntities.CustomerProperties.FirstOrDefault(m => m.CustomerPropertyGroupId == propertyGroup.CustomerPropertyGroupId &&
                                                                                  m.PropertyDesc.Equals(propertyGroupName) &&
                                                                                  m.CustomerID == customerId);

            if (customerProperty == null)
            {
                // Also create a CustomerProperty
                customerProperty = new CustomerProperty()
                {
                    CustomerPropertyGroupId = propertyGroup.CustomerPropertyGroupId,
                    CustomerID   = customerId,
                    PropertyDesc = propertyGroupName,
                    SortOrder    = 0
                };
                PemsEntities.CustomerProperties.Add(customerProperty);
                PemsEntities.SaveChanges();
            }

            // Get the CustomerDetails
            CustomerDetail customerDetail =
                PemsEntities.CustomerDetails.FirstOrDefault(m => m.CustomerID == customerId && m.CustomerPropertyId == customerProperty.CustomerPropertyId);

            if (customerDetail == null)
            {
                customerDetail = new CustomerDetail()
                {
                    CustomerID         = customerId,
                    CustomerPropertyId = customerProperty.CustomerPropertyId,
                    ScreenName         = propertyGroupName,
                    IsDisplay          = true,
                    IsRequired         = true
                };
                PemsEntities.CustomerDetails.Add(customerDetail);
            }
            customerDetail.AdditionalValue = propertyValue.ToString();

            PemsEntities.SaveChanges();
        }
Esempio n. 12
0
        private DataKey CreateDataKey(int customerId, Meter newMeter)
        {
            // Get customer TimeZoneId
            var customerProfile = RbacEntities.CustomerProfiles.FirstOrDefault(m => m.CustomerId == customerId);

            newMeter.TimeZoneID = customerProfile.TimeZoneID ?? 0;

            // Create an audit entry.
            Audit(newMeter);

            // Create a datakey
            var newItem = new DataKey()
            {
                //todo - GTC: DataKeys add dataKeyname here when db field is added - might have to pass in the datakey name
                DataKeyId       = newMeter.MeterId,//this is auto increment field, so thats why we have the datakeyidnumber field
                DataKeyIdNumber = newMeter.MeterId,
                CustomerID      = customerId,
            };

            PemsEntities.DataKeys.Add(newItem);
            PemsEntities.SaveChanges();

            // Add audit record
            Audit(newItem);

            //  Need a [HousingMaster]
            HousingMaster housingMaster = PemsEntities.HousingMasters.FirstOrDefault(m => m.HousingName.Equals("Default"));

            // Create a MeterMap record to join datakey and Meter
            MeterMap meterMap = new MeterMap()
            {
                Customerid = newMeter.CustomerID,
                Areaid     = newMeter.AreaID,
                MeterId    = newMeter.MeterId,
                DataKeyId  = newItem.DataKeyId,
                HousingId  = housingMaster.HousingId
            };

            PemsEntities.MeterMaps.Add(meterMap);
            PemsEntities.SaveChanges();
            return(newItem);
        }
Esempio n. 13
0
        public void UpdateFile_Active(PayByCellModel[] Griddata, int CustID)
        {
            try
            {
                foreach (var item in Griddata)
                {
                    if (item.MeterID == item.VendorID)
                    {
                        var stud = (from s in PemsEntities.TransactionsMParks
                                    where (s.CustomerID == CustID && s.MeterId == item.MeterID && s.AreaID == item.AreaID)
                                    select s).FirstOrDefault();

                        // stud.KeyText = KeyString + item.KeyText;
                        stud.VendorId = item.MeterID;
                        PemsEntities.SaveChanges();
                    }
                }
            }
            catch (Exception ex) { }
        }
Esempio n. 14
0
        /// <summary>
        /// Saves a discount scheme user account
        /// </summary>
        public void SaveUserAcount(UserAccountDetails userAccountDetails)
        {
            //ge the user acount
            var user = PemsEntities.Users.FirstOrDefault(x => x.UserID == userAccountDetails.UserId);

            if (user != null)
            {
                //only able to edit certain fields, so those are the ones we are saving.
                //email,phone, add 1 2, city, state, postal

                user.UserEmail    = userAccountDetails.Email;
                user.PhoneNumber  = userAccountDetails.Phone;
                user.UserAddress  = userAccountDetails.Address1;
                user.Address2     = userAccountDetails.Address2;
                user.City         = userAccountDetails.City;
                user.AddressState = userAccountDetails.State;
                user.PostalCode   = userAccountDetails.PostalCode;
                PemsEntities.SaveChanges();
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Rejects a discount scheme for a user
        /// </summary>
        public void RejectApplication(int userID, int userSchemeId, string notes, DateTime localTime)
        {
            //get the discountuserscheme
            var userScheme = UpdateSchemeStatus(userSchemeId, notes, localTime, 3, false);

            //create a audit log of the change
            if (userScheme != null)
            {
                AuditChanges(localTime, userScheme);
                //need to update count for approvedcount for this user.
                var user = PemsEntities.Users.FirstOrDefault(x => x.UserID == userID);
                if (user != null)
                {
                    user.RejectedCount++;
                    user.PendingCount--;
                    PemsEntities.SaveChanges();
                }
                //email user of action
                EmailStatusChange(userID, userScheme.SchemeId, Constants.DiscountScheme.RejectionEmailTemplateId);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Creates a clone (copy) of the <see cref="CashBox"/> refrenced by <paramref name="assetId"/> and <paramref name="customerId"/>.  This cloned
        /// <see cref="CashBox"/> is written to the [CashBox] table and the [AssetPending] table.
        /// </summary>
        /// <param name="customerId">The customer id</param>
        /// <param name="areaId">The area id (presently not used)</param>
        /// <param name="assetId">The cashbox id to clone</param>
        /// <returns>Integer representing the new cashbox id (<see cref="CashBox.CashBoxID"/>)</returns>
        private int Clone(int customerId, int areaId, Int64 assetId)
        {
            // Get original cashbox
            // Since this cashbox exists, this entity should exist also.
            CashBox cashbox = PemsEntities.CashBoxes.FirstOrDefault(m => m.CashBoxSeq == assetId && m.CustomerID == customerId);

            // Create a cashbox
            CashBox newCashbox = new CashBox()
            {
                // CashBoxID = NextCashBoxId(customerId),
                CustomerID                  = customerId,
                CashBoxSeq                  = NextCashBoxId(customerId), //cashbox.CashBoxSeq,
                CashBoxState                = (int)AssetStateType.Pending,
                CashBoxModel                = cashbox.CashBoxModel,
                CashBoxType                 = cashbox.CashBoxType,
                OperationalStatus           = (int)OperationalStatusType.Inactive,
                OperationalStatusTime       = DateTime.Now,
                NextPreventativeMaintenance = cashbox.NextPreventativeMaintenance,
                CashBoxName                 = "",
                WarrantyExpiration          = cashbox.WarrantyExpiration,
                CashBoxLocationTypeId       = cashbox.CashBoxLocationTypeId
            };

            PemsEntities.CashBoxes.Add(newCashbox);
            PemsEntities.SaveChanges();

            // Set audit records.
            Audit(newCashbox);

            // Add AssetPending record
            (new PendingFactory(ConnectionStringName, Now)).SetImportPending(AssetTypeModel.AssetType.Cashbox,
                                                                             SetToMidnight(Now),
                                                                             AssetStateType.Current,
                                                                             customerId,
                                                                             newCashbox.CashBoxID,
                                                                             (int)AssetStateType.Pending, (int)OperationalStatusType.Inactive,
                                                                             (int)AssetAreaId.Cashbox);

            return(newCashbox.CashBoxSeq);
        }
Esempio n. 17
0
        /// <summary>
        /// updates the status of a discountuser scheme with notes
        /// </summary>
        private DiscountUserScheme UpdateSchemeStatus(int userSchemeId, string notes, DateTime localTime, int statusId,
                                                      bool setExpiry = true)
        {
            //get the discountuserscheme
            var userScheme = PemsEntities.DiscountUserSchemes.FirstOrDefault(x => x.DiscountUserSchemeId == userSchemeId);

            if (userScheme != null)
            {
                //update the item in the db with the new status, notes, last mod by, and status date
                userScheme.StatusNote       = notes;
                userScheme.ModifiedByUserId = WebSecurity.CurrentUserId;
                userScheme.SchemeStatusDate = localTime;
                userScheme.SchemeStatus     = statusId;

                //we only set a exp if its an approved, not a rejected

                if (setExpiry)
                {
                    //we have to set the expiration date of the discount user scheme to the expiration duration of the discount scheme.

                    //we will default it to a year if they dont have an expiration set rof rthis discount scheme
                    var originalDiscountSchemeID     = userScheme.DiscountScheme.DiscountSchemeExpirationTypeId ?? 1;
                    var discountSchemeExpirationType = (DiscountExpirationType)originalDiscountSchemeID;
                    if (discountSchemeExpirationType == DiscountExpirationType.Monthly)
                    {
                        userScheme.ExpiryTS = localTime.AddMonths(1);
                    }
                    else if (discountSchemeExpirationType == DiscountExpirationType.Weekly)
                    {
                        userScheme.ExpiryTS = localTime.AddDays(7);
                    }
                    else if (discountSchemeExpirationType == DiscountExpirationType.Yearly)
                    {
                        userScheme.ExpiryTS = localTime.AddYears(1);
                    }
                }
                PemsEntities.SaveChanges();
            }
            return(userScheme);
        }
Esempio n. 18
0
        /// <summary>
        /// Records a approval or rejection int he DB
        /// </summary>
        private void AuditChanges(DateTime localTime, DiscountUserScheme userScheme)
        {
            var audit = new DiscountUserSchemeAudit
            {
                CardId               = userScheme.CardId,
                ChangedByUserId      = WebSecurity.CurrentUserId,
                ChangedDate          = localTime,
                CreatedTS            = userScheme.CreatedTS,
                CustomerId           = userScheme.CustomerId,
                DiscountUserSchemeId = userScheme.DiscountUserSchemeId,
                ExpiryTS             = userScheme.ExpiryTS,
                ModifiedByUserId     = userScheme.ModifiedByUserId,
                SchemeId             = userScheme.SchemeId,
                SchemeStatus         = userScheme.SchemeStatus,
                SchemeStatusDate     = userScheme.SchemeStatusDate,
                StatusNote           = userScheme.StatusNote,
                UserId               = userScheme.UserId
            };

            PemsEntities.DiscountUserSchemeAudits.Add(audit);
            PemsEntities.SaveChanges();
        }
Esempio n. 19
0
        /// <summary>
        /// Sets a customer property
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="propertyGroupItem"></param>
        /// <param name="enabled"></param>
        public void Set(int customerId, PropertyGroupItem propertyGroupItem, bool enabled)
        {
            // Get the CustomerDetails
            CustomerDetail customerDetail =
                PemsEntities.CustomerDetails.FirstOrDefault(m => m.CustomerID == customerId && m.CustomerPropertyId == propertyGroupItem.Id);

            if (customerDetail == null)
            {
                customerDetail = new CustomerDetail()
                {
                    CustomerID         = customerId,
                    CustomerPropertyId = propertyGroupItem.Id,
                    AdditionalValue    = null,
                    ScreenName         = propertyGroupItem.Value,
                    IsRequired         = true
                };
                PemsEntities.CustomerDetails.Add(customerDetail);
            }

            customerDetail.IsDisplay = enabled;

            PemsEntities.SaveChanges();
        }
Esempio n. 20
0
        /// <summary>
        /// sets the event code edit model with the event code data in the system
        /// </summary>
        /// <param name="model"></param>
        public void SetEventCodeEditModel(EventCodeEditModel model)
        {
            // Get the original EventCode
            var eventCode = PemsEntities.EventCodes.FirstOrDefault(m => m.CustomerID == model.CustomerId && m.EventSource == model.SourceId && m.EventCode1 == model.Id);

            if (eventCode != null)
            {
                eventCode.AlarmTier        = model.AlarmTierId;
                eventCode.EventDescAbbrev  = model.DescAbbrev;
                eventCode.EventDescVerbose = model.DescVerbose;
                eventCode.SLAMinutes       = model.ApplySLA ? model.SLAMinutes : null;
                eventCode.ApplySLA         = model.ApplySLA;
                eventCode.IsAlarm          = model.IsAlarm;
                eventCode.EventType        = model.TypeId;
                eventCode.EventCategory    = model.CategoryId;

                // Insert/update [EventCodeAssetType]
                var ecat = PemsEntities.EventCodeAssetTypes.FirstOrDefault(m => m.CustomerID == model.CustomerId && m.EventSource == model.SourceId && m.EventCode == model.Id);
                if (ecat == null)
                {
                    ecat = new EventCodeAssetType()
                    {
                        CustomerID  = model.CustomerId,
                        EventSource = model.SourceId,
                        EventCode   = model.Id,
                    };
                    PemsEntities.EventCodeAssetTypes.Add(ecat);
                }
                ecat.MeterGroupId = model.AssetTypeId;

                // Save changes
                PemsEntities.SaveChanges();

                // Add audit record.
                Audit(eventCode);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Clears an alarm. Creates a historic alarm, maintenance event, and removed the current active alarm from the system.
        /// </summary>
        public void ClearAlarm(AlarmModel model)
        {
            //get the original alarm item
            var alarm =
                PemsEntities.ActiveAlarms.FirstOrDefault(
                    x =>
                    x.CustomerID == model.CustomerId && x.AreaID == model.AreaId && x.MeterId == model.AssetID &&
                    x.EventCode == model.AlarmCode && x.EventSource == model.EventSource &&
                    x.TimeOfOccurrance == model.TimeOccured);

            if (alarm != null)
            {
                //first, we have to check for a work order, and if it doesnt exist, create one so we can link the new historical alarm to the sf maint event.
                if (!alarm.WorkOrderId.HasValue)
                {
                    var wOrder = new WorkOrder
                    {
                        AssignedBy   = WebSecurity.CurrentUserId,
                        AssignedTS   = DateTime.Now,
                        CustomerID   = model.CustomerId,
                        TechnicianID = model.TechnicianID
                    };
                    PemsEntities.WorkOrders.Add(wOrder);
                    PemsEntities.SaveChanges();

                    //now assign the alarm the newly created work order id
                    alarm.WorkOrderId = wOrder.WorkOrderId;
                    PemsEntities.SaveChanges();
                }

                //now lets calculate the service designation
                SetTSDS(alarm.CustomerID);
                var masterId = GetTsdMasterId(model.TimeCleared, alarm.SLADue);
                //calculate the target  service designnation here as well
                var tds = Tsds.FirstOrDefault(x => x.MasterId == masterId);

                //we will try to update an existing historical alarm if it already exists, otherwise we will insert a new one.
                //there is some old data that has duplicates in the historical and active, so this gracefully takes care of that, since all we want to do if the historical alarm exist is update the record with the active alarm information.
                var ExistinghistoricAlarm =
                    PemsEntities.HistoricalAlarms.FirstOrDefault(
                        x => x.CustomerID == alarm.CustomerID && x.AreaID == alarm.AreaID && x.MeterId == alarm.MeterId &&
                        x.EventCode == alarm.EventCode && x.EventSource == alarm.EventSource &&
                        x.TimeOfOccurrance == alarm.TimeOfOccurrance && x.EventState == 0);

                //if it was found, we have to delete the historical item and re-create one, since the eventUID is an identity column, we cant change it, but its not part of the primary key, so it might need to change.
                //So, we have to try to get the hsitorical alarm, delete it, then try to create a new one.
                if (ExistinghistoricAlarm != null)
                {
                    PemsEntities.HistoricalAlarms.Remove(ExistinghistoricAlarm);
                    PemsEntities.SaveChanges();
                }
                //Now we need to create a new one
                //we have to insert a historical alarm
                var historicAlarm = new HistoricalAlarm
                {
                    AlarmUID           = alarm.AlarmUID,
                    AreaID             = alarm.AreaID,
                    ClearedByUserId    = model.ClosedBy,
                    ClearingEventUID   = 0,
                    ClosureNote        = model.ClosureNotes,
                    CustomerID         = alarm.CustomerID,
                    EventCode          = alarm.EventCode,
                    EventSource        = alarm.EventSource,
                    EventState         = 0,
                    EventUID           = (int)(alarm.EventUID ?? 0),
                    GlobalMeterId      = alarm.GlobalMeterID,
                    MeterId            = alarm.MeterId,
                    Notes              = alarm.Notes,
                    SLADue             = alarm.SLADue,
                    TimeOfClearance    = model.TimeCleared,
                    TimeOfNotification = alarm.TimeOfNotification,
                    TimeOfOccurrance   = alarm.TimeOfOccurrance,
                    TimeType1          = alarm.TimeType1,
                    TimeType2          = alarm.TimeType2,
                    TimeType3          = alarm.TimeType3,
                    TimeType4          = alarm.TimeType4,
                    TimeType5          = alarm.TimeType5,
                    WorkOrderId        = alarm.WorkOrderId
                };
                //now determine the correct TSD Master
                if (tds != null)
                {
                    historicAlarm.TargetServiceDesignation = tds.Id;
                }

                PemsEntities.HistoricalAlarms.Add(historicAlarm);
                PemsEntities.SaveChanges();

                //we also need ot create a valid SFMeterMAintenanceEvent
                var maintenanceEvent = new SFMeterMaintenanceEvent
                {
                    AreaId          = alarm.AreaID,
                    CustomerId      = alarm.CustomerID,
                    EventDateTime   = model.ClosureNotification,
                    GlobalMeterId   = alarm.GlobalMeterID,
                    MaintenanceCode = model.ResolutionCode,
                    MeterId         = alarm.MeterId,
                    TechnicianId    = model.TechnicianID,
                    WorkOrderID     = alarm.WorkOrderId
                };
                PemsEntities.SFMeterMaintenanceEvents.Add(maintenanceEvent);
                PemsEntities.SaveChanges();

                //now we must delete the alarm we jsut cleared
                PemsEntities.ActiveAlarms.Remove(alarm);
                PemsEntities.SaveChanges();
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Created an event code int he system
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int CreateEventCode(EventCodeEditModel model)
        {
            EventCode eventCode = null;

            // Get next EventCode id for a given customer & EventSource.
            // If model.Id is non-zero then a particular event code id has been requested.

            int nextId = model.Id;

            eventCode = PemsEntities.EventCodes.FirstOrDefault(m => m.CustomerID == model.CustomerId && m.EventSource == model.SourceId && m.EventCode1 == nextId);
            if (eventCode == null)
            {
                if (nextId < 0)
                {
                    nextId    = 1;
                    eventCode = PemsEntities.EventCodes.FirstOrDefault(m => m.CustomerID == model.CustomerId && m.EventSource == model.SourceId);
                    if (eventCode != null)
                    {
                        nextId = PemsEntities.EventCodes.Where(m => m.CustomerID == model.CustomerId && m.EventSource == model.SourceId).Max(m => m.EventCode1) + 1;
                    }
                }

                // Create the new EventCode
                eventCode = new EventCode()
                {
                    CustomerID       = model.CustomerId,
                    EventSource      = model.SourceId,
                    EventCode1       = nextId,
                    AlarmTier        = model.AlarmTierId,
                    EventDescAbbrev  = model.DescAbbrev,
                    EventDescVerbose = model.DescVerbose,
                    SLAMinutes       = model.ApplySLA ? model.SLAMinutes : null,
                    ApplySLA         = model.ApplySLA,
                    IsAlarm          = model.IsAlarm,
                    EventType        = model.TypeId,
                    EventCategory    = model.CategoryId
                };
                PemsEntities.EventCodes.Add(eventCode);
                PemsEntities.SaveChanges();
            }
            else
            {
                eventCode.AlarmTier        = model.AlarmTierId;
                eventCode.EventDescAbbrev  = model.DescAbbrev;
                eventCode.EventDescVerbose = model.DescVerbose;
                eventCode.SLAMinutes       = model.ApplySLA ? model.SLAMinutes : null;
                eventCode.ApplySLA         = model.ApplySLA;
                eventCode.IsAlarm          = model.IsAlarm;
                eventCode.EventType        = model.TypeId;
                eventCode.EventCategory    = model.CategoryId;
                PemsEntities.SaveChanges();
            }

            // Insert/update [EventCodeAssetType]
            var ecat = PemsEntities.EventCodeAssetTypes.FirstOrDefault(m => m.CustomerID == model.CustomerId && m.EventSource == model.SourceId && m.EventCode == nextId);

            if (ecat == null)
            {
                ecat = new EventCodeAssetType()
                {
                    CustomerID  = model.CustomerId,
                    EventSource = model.SourceId,
                    EventCode   = nextId,
                };
                PemsEntities.EventCodeAssetTypes.Add(ecat);
            }
            ecat.MeterGroupId = model.AssetTypeId;

            // Save changes
            PemsEntities.SaveChanges();

            // Add audit record.
            Audit(eventCode);

            // Return new EventCode id
            return(nextId);
        }
Esempio n. 23
0
        public void AddAdminLevelAutoAlarm(string LowBattPollInterval, string LowBattAlarmClearVolt, string LowBattCritLowBattVolt,
                                           string LowBattLowBattVolt, string LowBattSampleSinceHrs, string LowBattSsmVoltDiagType, string NoCommPollTime)
        {
            try
            {
                var ripprop = PemsEntities.RipnetProperties.FirstOrDefault(c => c.KeyText.Contains("Databus.AutoAlarm.EventSource"));
                if (ripprop != null)
                {
                    ripprop.ValueText = "0"; //indicates meter
                    PemsEntities.SaveChanges();
                }
                else
                {
                    RipnetProperty DuncanProp = new RipnetProperty();
                    DuncanProp.KeyText   = "Databus.AutoAlarm.EventSource";
                    DuncanProp.ValueText = "0"; //indicates meter
                    PemsEntities.RipnetProperties.Add(DuncanProp);
                    PemsEntities.SaveChanges();
                }

                ripprop = PemsEntities.RipnetProperties.FirstOrDefault(c => c.KeyText.Contains("Databus.AutoAlarm.LowBatt.PollInterval"));
                if (ripprop != null)
                {
                    ripprop.ValueText = LowBattPollInterval; //indicates meter
                    PemsEntities.SaveChanges();
                }
                else
                {
                    RipnetProperty DuncanProp = new RipnetProperty();
                    DuncanProp.KeyText   = "Databus.AutoAlarm.LowBatt.PollInterval";
                    DuncanProp.ValueText = LowBattPollInterval;
                    PemsEntities.RipnetProperties.Add(DuncanProp);
                    PemsEntities.SaveChanges();
                }

                ripprop = PemsEntities.RipnetProperties.FirstOrDefault(c => c.KeyText.Contains("Databus.AutoAlarm.LowBatt.AlarmClearVolt"));
                if (ripprop != null)
                {
                    ripprop.ValueText = LowBattAlarmClearVolt;
                    PemsEntities.SaveChanges();
                }
                else
                {
                    RipnetProperty DuncanProp = new RipnetProperty();
                    DuncanProp.KeyText   = "Databus.AutoAlarm.LowBatt.AlarmClearVolt";
                    DuncanProp.ValueText = LowBattAlarmClearVolt;
                    PemsEntities.RipnetProperties.Add(DuncanProp);
                    PemsEntities.SaveChanges();
                }

                ripprop = PemsEntities.RipnetProperties.FirstOrDefault(c => c.KeyText.Contains("Databus.AutoAlarm.LowBatt.CritLowBattVolt"));
                if (ripprop != null)
                {
                    ripprop.ValueText = LowBattCritLowBattVolt;
                    PemsEntities.SaveChanges();
                }
                else
                {
                    RipnetProperty DuncanProp = new RipnetProperty();
                    DuncanProp.KeyText   = "Databus.AutoAlarm.LowBatt.CritLowBattVolt";
                    DuncanProp.ValueText = LowBattCritLowBattVolt;
                    PemsEntities.RipnetProperties.Add(DuncanProp);
                    PemsEntities.SaveChanges();
                }

                ripprop = PemsEntities.RipnetProperties.FirstOrDefault(c => c.KeyText.Contains("Databus.AutoAlarm.LowBatt.LowBattVolt"));
                if (ripprop != null)
                {
                    ripprop.ValueText = LowBattLowBattVolt;
                    PemsEntities.SaveChanges();
                }
                else
                {
                    RipnetProperty DuncanProp = new RipnetProperty();
                    DuncanProp.KeyText   = "Databus.AutoAlarm.LowBatt.LowBattVolt";
                    DuncanProp.ValueText = LowBattLowBattVolt;
                    PemsEntities.RipnetProperties.Add(DuncanProp);
                    PemsEntities.SaveChanges();
                }

                ripprop = PemsEntities.RipnetProperties.FirstOrDefault(c => c.KeyText.Contains("Databus.AutoAlarm.LowBatt.SampleSinceHrs"));
                if (ripprop != null)
                {
                    ripprop.ValueText = LowBattSampleSinceHrs;
                    PemsEntities.SaveChanges();
                }
                else
                {
                    RipnetProperty DuncanProp = new RipnetProperty();
                    DuncanProp.KeyText   = "Databus.AutoAlarm.LowBatt.SampleSinceHrs";
                    DuncanProp.ValueText = LowBattSampleSinceHrs;
                    PemsEntities.RipnetProperties.Add(DuncanProp);
                    PemsEntities.SaveChanges();
                }

                ripprop = PemsEntities.RipnetProperties.FirstOrDefault(c => c.KeyText.Contains("Databus.AutoAlarm.LowBatt.SsmVoltDiagType"));
                if (ripprop != null)
                {
                    ripprop.ValueText = LowBattSsmVoltDiagType;
                    PemsEntities.SaveChanges();
                }
                else
                {
                    RipnetProperty DuncanProp = new RipnetProperty();
                    DuncanProp.KeyText   = "Databus.AutoAlarm.LowBatt.SsmVoltDiagType";
                    DuncanProp.ValueText = PemsEntities.MeterDiagnosticTypes.FirstOrDefault(e => e.DiagnosticDesc == LowBattSsmVoltDiagType).ID.ToString();
                    PemsEntities.RipnetProperties.Add(DuncanProp);
                    PemsEntities.SaveChanges();
                }

                ripprop = PemsEntities.RipnetProperties.FirstOrDefault(c => c.KeyText.Contains("Databus.AutoAlarm.NoComm.PollTime"));
                if (ripprop != null)
                {
                    ripprop.ValueText = NoCommPollTime;
                    PemsEntities.SaveChanges();
                }
                else
                {
                    RipnetProperty DuncanProp = new RipnetProperty();
                    DuncanProp.KeyText   = "Databus.AutoAlarm.NoComm.PollTime";
                    DuncanProp.ValueText = NoCommPollTime;
                    PemsEntities.RipnetProperties.Add(DuncanProp);
                    PemsEntities.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 24
0
        private int Clone(int customerId, Int64 assetId)
        {
            // Get original datakey and its associated Meter and MeterMap
            // Since this exists, these entities should exist also.
            DataKey dataKey = PemsEntities.DataKeys.FirstOrDefault(m => m.DataKeyId == assetId);

            if (dataKey != null)
            {
                MeterMap meterMap = dataKey.MeterMaps.FirstOrDefault(m => m.DataKeyId == dataKey.DataKeyId);
                if (meterMap != null)
                {
                    Meter meter = meterMap.Meter;

                    // Create the new meter that is associated with the datakey type of asset.  This is not a meter
                    // but rather a an asset in the meter table that represents a datakey.
                    Meter newMeter = CreateBaseAsset(meter.CustomerID, MeterGroups.Datakey, meter.AreaID);

                    // Create a datakey
                    var clonedItem = new DataKey()
                    {
                        //todo - GTC: DataKeys add datakeyname here when db field is added
                        DataKeyDesc = dataKey.DataKeyDesc,
                        DataKeyId   = newMeter.MeterId,
                        //this is auto increment, so it wont save the value, its why we have the datakeyidnumber column.
                        DataKeyIdNumber = newMeter.MeterId,
                        DataKeyType     = dataKey.DataKeyType,
                        CustomerID      = customerId
                    };

                    PemsEntities.DataKeys.Add(clonedItem);
                    PemsEntities.SaveChanges();

                    // Add AssetPending record
                    (new PendingFactory(ConnectionStringName, Now)).SetImportPending(
                        AssetTypeModel.AssetType.DataKey, SetToMidnight(Now), AssetStateType.Current, customerId,
                        clonedItem.DataKeyIdNumber.GetValueOrDefault(), (int)AssetStateType.Pending, (int)OperationalStatusType.Inactive, (int)AssetAreaId.DataKey);

                    // Align clonable meter fields.
                    newMeter.Location                    = meter.Location;
                    newMeter.DemandZone                  = meter.DemandZone;
                    newMeter.FreeParkingMinute           = meter.FreeParkingMinute;
                    newMeter.MeterGroup                  = meter.MeterGroup;
                    newMeter.MeterName                   = meter.MeterName;
                    newMeter.MeterType                   = meter.MeterType;
                    newMeter.TimeZoneID                  = meter.TimeZoneID;
                    newMeter.TypeCode                    = meter.TypeCode;
                    newMeter.WarrantyExpiration          = meter.WarrantyExpiration;
                    newMeter.NextPreventativeMaintenance = meter.NextPreventativeMaintenance;

                    // Create meter map for cloned item.
                    //  Need a [HousingMaster]
                    HousingMaster housingMaster =
                        PemsEntities.HousingMasters.FirstOrDefault(m => m.HousingName.Equals("Default"));

                    // Create a [MeterMap] entry
                    MeterMap newMeterMap = new MeterMap()
                    {
                        Customerid = newMeter.CustomerID,
                        Areaid     = newMeter.AreaID,
                        MeterId    = newMeter.MeterId,
                        DataKeyId  = clonedItem.DataKeyId,
                        HousingId  = housingMaster.HousingId
                    };
                    PemsEntities.MeterMaps.Add(newMeterMap);
                    PemsEntities.SaveChanges();

                    newMeterMap.AreaId2      = meterMap.AreaId2;
                    newMeterMap.ZoneId       = meterMap.ZoneId;
                    newMeterMap.SubAreaID    = meterMap.SubAreaID;
                    newMeterMap.CustomGroup1 = meterMap.CustomGroup1;
                    newMeterMap.CustomGroup2 = meterMap.CustomGroup2;
                    newMeterMap.CustomGroup3 = meterMap.CustomGroup3;
                    newMeterMap.MaintRouteId = meterMap.MaintRouteId;

                    PemsEntities.SaveChanges();

                    // Set audit records.
                    Audit(newMeter);
                    Audit(newMeterMap);
                    Audit(clonedItem);

                    return(clonedItem.DataKeyIdNumber.GetValueOrDefault());
                }
            }
            return(0);
        }
Esempio n. 25
0
        /// <summary>
        /// Sets a customer property
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="propertyGroupName"></param>
        /// <param name="propertyValue"></param>
        public void Set(int customerId, string propertyGroupName, string propertyValue)
        {
            bool isListItem = true;

            var propertyGroup = GetCustomerPropertyGroup(customerId, propertyGroupName);

            // This propertyValue may be a list item.  That can be confirmed if
            // the CustomerProperty && CustomerPropertyGroup can be matched.  Otherwise this is
            // probably a single-value proprty.


            CustomerProperty customerProperty = PemsEntities.CustomerProperties.FirstOrDefault(m => m.CustomerPropertyGroupId == propertyGroup.CustomerPropertyGroupId &&
                                                                                               m.PropertyDesc.Equals(propertyValue) &&
                                                                                               m.CustomerID == customerId);

            if (customerProperty == null)
            {
                // The customerProperty is a single-value type.  See if it already exists.

                customerProperty = PemsEntities.CustomerProperties.FirstOrDefault(m => m.CustomerPropertyGroupId == propertyGroup.CustomerPropertyGroupId &&
                                                                                  m.PropertyDesc.Equals(propertyGroupName) &&
                                                                                  m.CustomerID == customerId);
                // Create asingle-value  CustomerProperty
                if (customerProperty == null)
                {
                    customerProperty = new CustomerProperty()
                    {
                        CustomerPropertyGroupId = propertyGroup.CustomerPropertyGroupId,
                        CustomerID   = customerId,
                        PropertyDesc = propertyGroupName,
                        SortOrder    = 0
                    };
                    PemsEntities.CustomerProperties.Add(customerProperty);
                    PemsEntities.SaveChanges();
                }
                isListItem = false;
            }

            // Get the CustomerDetails
            CustomerDetail customerDetail =
                PemsEntities.CustomerDetails.FirstOrDefault(m => m.CustomerID == customerId && m.CustomerPropertyId == customerProperty.CustomerPropertyId);

            if (customerDetail == null)
            {
                customerDetail = new CustomerDetail()
                {
                    CustomerID         = customerId,
                    CustomerPropertyId = customerProperty.CustomerPropertyId,
                    AdditionalValue    = (isListItem ? null : propertyValue),
                    ScreenName         = propertyGroupName,
                    IsDisplay          = true,
                    IsRequired         = true
                };
                PemsEntities.CustomerDetails.Add(customerDetail);
            }
            else
            {
                customerDetail.CustomerPropertyId = customerProperty.CustomerPropertyId;
                customerDetail.AdditionalValue    = (isListItem ? null : propertyValue);
            }

            PemsEntities.SaveChanges();
        }