Пример #1
0
        /// <summary>
        /// Update a single user setting
        /// </summary>
        /// <param name="userId">Id of user</param>
        /// <param name="settingName">Name of setting</param>
        /// <param name="settingValue">Value of setting</param>
        public void Set(int userId, string settingName, string settingValue)
        {
            //we may want to set it to empty string, since we might want to set it to empty sometimes
            if (settingValue == null)
            {
                settingValue = string.Empty;
            }
            // Does this customer already have one of these settings?
            var setting = RbacEntities.UserSettings.FirstOrDefault(userSetting => userSetting.UserId == userId
                                                                   &&
                                                                   userSetting.SettingName ==
                                                                   settingName);

            if (setting == null)
            {
                // Create new customer setting entry
                setting = new UserSetting()
                {
                    UserId       = userId,
                    SettingName  = settingName,
                    SettingValue = settingValue
                };
                RbacEntities.UserSettings.Add(setting);
            }
            else
            {
                setting.SettingValue = settingValue;
            }
            RbacEntities.SaveChanges();
        }
Пример #2
0
        /// <summary>
        /// Saves a new audit record
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="primaryKey"></param>
        /// <param name="auditRecord"></param>
        public void Set(string tableName, int primaryKey, AuditRecord auditRecord)
        {
            // Handle table CustomerProfile
            if (tableName.Equals("CustomerProfile"))
            {
                SetCustomerProfile(primaryKey, auditRecord);
                return;
            }

            // Default handling.
            SystemInformation si = new SystemInformation()
            {
                TableName  = tableName,
                PrimaryKey = primaryKey,
                CreatedBy  = auditRecord.CreatedBy,
                CreatedOn  = auditRecord.CreatedOn
            };

            if (auditRecord.ModifiedBy > 0)
            {
                si.LastModifiedBy = auditRecord.ModifiedBy;
                si.LastModifiedOn = auditRecord.ModifiedOn;
            }

            RbacEntities.SystemInformations.Add(si);
            RbacEntities.SaveChanges();
        }
        public void SetIdentificationModel(int customerId, MaintenanceGroupIdentificationModel identificationModel)
        {
            var customerProfile = RbacEntities.CustomerProfiles.SingleOrDefault(m => m.CustomerId == customerId);

            if (customerProfile == null)
            {
                return;
            }

            customerProfile.DisplayName = identificationModel.DisplayName;

            var settingFactory = new SettingsFactory();

            if (identificationModel.DefaultPassword != null)
            {
                settingFactory.Set(customerId, "DefaultPassword", identificationModel.DefaultPassword);
            }

            // Save customer contact
            SetCustomerContactModel(customerId, identificationModel.Contact);

            // Save Customer Localization data.
            SetCustomerLocalizationModel(customerId, identificationModel.Localization);

            RbacEntities.SaveChanges();
        }
        public void SetCustomerLocalizationModel(int customerId, CustomerLocalizationModel customerLocalizationModel)
        {
            var customerProfile = RbacEntities.CustomerProfiles.FirstOrDefault(m => m.CustomerId == customerId);

            // Language
            var     settingFactory = new SettingsFactory();
            Setting setting        = settingFactory.GetListValue("Locale", customerLocalizationModel.LanguageId);

            if (setting != null)
            {
                settingFactory.Set(customerId, "CustomerLocale", setting.Value);

                // Write the local to customer.DefaultLocale also
                customerProfile.DefaultLocale = setting.Value;
            }


            // 12/ 24 hour format
            customerProfile.Is24HrFormat = customerLocalizationModel.Is24Hr;

            // TimeZone
            customerProfile.TimeZoneID = customerLocalizationModel.TimeZoneId;
            // Save changes.
            RbacEntities.SaveChanges();
        }
Пример #5
0
        /// <summary>
        /// Sets / Updates the modification information for an item
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="primaryKey"></param>
        /// <param name="userId"></param>
        public void ModifiedBy(string tableName, int primaryKey, int userId)
        {
            // Handle table CustomerProfile
            if (tableName.Equals("CustomerProfile"))
            {
                ModifiedByCustomerProfile(primaryKey, userId);
                return;
            }

            // Default handling.
            var rbacAuditRecord = RbacEntities.SystemInformations.FirstOrDefault(ar => ar.TableName == tableName && ar.PrimaryKey == primaryKey);

            if (rbacAuditRecord != null)
            {
                rbacAuditRecord.LastModifiedBy = userId;
                rbacAuditRecord.LastModifiedOn = DateTime.Now;
                RbacEntities.SaveChanges();
            }
            else
            {
                //if it doesnt exist, create and update
                AuditRecord auditRecord = new AuditRecord()
                {
                    CreatedBy  = userId,
                    CreatedOn  = DateTime.Now,
                    ModifiedOn = DateTime.Now,
                    ModifiedBy = userId
                };
                Set(tableName, primaryKey, auditRecord);
            }
        }
Пример #6
0
        /// <summary>
        /// Update user settings via a list of <see cref="Setting"/>
        /// </summary>
        /// <param name="userId">Id of user</param>
        /// <param name="settings">List of <see cref="Setting"/></param>
        public void Set(int userId, List <Setting> settings)
        {
            foreach (var newSetting in settings)
            {
                if (!string.IsNullOrEmpty(newSetting.Value))
                {
                    // Does this customer already have one of these settings?
                    var setting = RbacEntities.UserSettings.FirstOrDefault(userSetting => userSetting.UserId == userId
                                                                           &&
                                                                           userSetting.SettingName ==
                                                                           newSetting.Name);

                    if (setting == null)
                    {
                        // Create new customer setting entry
                        setting = new UserSetting()
                        {
                            UserId       = userId,
                            SettingName  = newSetting.Name,
                            SettingValue = newSetting.Value
                        };
                        RbacEntities.UserSettings.Add(setting);
                    }
                    else
                    {
                        setting.SettingValue = newSetting.Value;
                    }
                }
            }
            RbacEntities.SaveChanges();
        }
Пример #7
0
        /// <summary>
        /// Updates a user's profile
        /// </summary>
        public void UnLockUser(string username)
        {
            var profile = RbacEntities.UserProfiles.FirstOrDefault(u => u.UserName == username);

            if (profile != null)
            {
                profile.Membership.PasswordFailuresSinceLastSuccess = 0;
                RbacEntities.SaveChanges();
            }
        }
Пример #8
0
        /// <summary>
        /// Updates a user's profile
        /// </summary>
        public void UpdateUserStatus(string userName, bool active)
        {
            var profile = RbacEntities.UserProfiles.FirstOrDefault(u => u.UserName == userName);

            if (profile == null)
            {
                return;
            }
            profile.Membership.IsActive = active;
            RbacEntities.SaveChanges();
        }
Пример #9
0
        /// <summary>
        /// Updates a user to update their PW reset value
        /// </summary>
        public void UpdateUserPasswordReset(string username, bool requirePasswordReset)
        {
            var profile = RbacEntities.UserProfiles.FirstOrDefault(u => u.UserName == username);

            if (profile == null)
            {
                return;
            }
            profile.RequirePasswordReset = requirePasswordReset;
            RbacEntities.SaveChanges();
        }
        public void Inactivate(int customerId)
        {
            var customerProfile = RbacEntities.CustomerProfiles.SingleOrDefault(m => m.CustomerId == customerId);

            if (customerProfile != null)
            {
                customerProfile.Status           = (int)CustomerStatus.Inactive;
                customerProfile.StatusChangeDate = DateTime.Now;
                RbacEntities.SaveChanges();
            }
        }
Пример #11
0
        /// <summary>
        /// Description: This Method will reorder postion , title and should be hidden or not
        /// ModifiedBy: Santhosh  (28/July/2014 - 04/Aug/2014)
        /// </summary>
        /// <param name="GridRowdata"></param>
        /// <returns></returns>
        public int UpdateCustomGridDetails(GridController GridRowdata)
        {
            var CG = (from ag in RbacEntities.CustomerGrids
                      where ag.CustomerGridsId == GridRowdata.CustomerGridsId
                      select ag).FirstOrDefault();

            CG.Position = GridRowdata.Position;
            CG.Title    = GridRowdata.Title;
            CG.IsHidden = GridRowdata.IsHidden;
            int num = RbacEntities.SaveChanges();

            return(num);
        }
Пример #12
0
        /// <summary>
        /// Updates the creation inforamtion for a customer profile
        /// </summary>
        /// <param name="primaryKey"></param>
        /// <param name="userId"></param>
        private void CreatedByCustomerProfile(int primaryKey, int userId)
        {
            var table = RbacEntities.CustomerProfiles.FirstOrDefault(cp => cp.CustomerId == primaryKey);

            if (table == null)
            {
                return;
            }

            table.CreatedBy = userId;
            table.CreatedOn = DateTime.Now;

            RbacEntities.SaveChanges();
        }
Пример #13
0
        /// <summary>
        /// udpates a customer profile creation and modification time
        /// </summary>
        /// <param name="primaryKey"></param>
        /// <param name="auditRecord"></param>
        private void SetCustomerProfile(int primaryKey, AuditRecord auditRecord)
        {
            var table = RbacEntities.CustomerProfiles.FirstOrDefault(cp => cp.CustomerId == primaryKey);

            if (table == null)
            {
                return;
            }

            table.CreatedBy  = auditRecord.CreatedBy;
            table.CreatedOn  = auditRecord.CreatedOn;
            table.ModifiedBy = auditRecord.ModifiedBy;
            table.ModifiedOn = auditRecord.ModifiedOn;

            RbacEntities.SaveChanges();
        }
        public int CreateNewMaintananceGroup(MaintenangeGroupCreateModel model, string templateFolder, string workingFolder)
        {
            // In order to create a new maintenance group
            // 1.  Create customer in AuthorizationManager
            // 3.  Create the customer (customer profile) in the RBAC database.
            // 6.  Create menu and authorization entries in NetSqlAzMan
            // 7.  Add the current user to the list in the cache table

            int customerId = 0;

            var authorizationManager = new AuthorizationManager();

            if (authorizationManager.CreateCity(model.Id, model.DisplayName, "Internal Name: " + model.InternalName))
            {
                var customerProfile = new CustomerProfile()
                {
                    CustomerId       = model.Id,
                    DisplayName      = model.DisplayName,
                    CreatedOn        = DateTime.Now,
                    CreatedBy        = WebSecurity.CurrentUserId,
                    StatusChangeDate = DateTime.Now,
                    Is24HrFormat     = false,
                    MaintenanceConnectionStringName = model.ConnectionStringName,
                    CustomerTypeId = (int)CustomerProfileType.MaintenanceGroup,
                    Status         = (int)CustomerStatus.New
                };
                RbacEntities.CustomerProfiles.Add(customerProfile);
                RbacEntities.SaveChanges();
                customerId = model.Id;
            }


            if (customerId != 0)
            {
                // Set the menus into RBAC
                SetMenus(model.DisplayName, templateFolder, workingFolder, MaintenanceGroupTemplateName);

                //NOTE: We dont need to do this, no need to custom hidden columns for maintenanceGroups
                // RbacEntities.InitializeCustomerGrids(customerId);

                //add the current customer to the access caching table
                (new UserCustomerAccessManager()).AddCustomerAccess(WebSecurity.CurrentUserId, customerId);
            }

            return(customerId);
        }
Пример #15
0
        /// <summary>
        /// Sets a customer setting
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="settingName"></param>
        /// <param name="settingValue"></param>
        public void Set(int customerId, string settingName, string settingValue)
        {
            if (settingValue == null)
            {
                settingValue = string.Empty;
            }
            var settingType = RbacEntities.CustomerSettingTypes.FirstOrDefault(x => x.CustomerSettingTypeName == settingName);

            if (settingType == null)
            {
                settingType = new CustomerSettingType()
                {
                    CustomerSettingTypeName = settingName,
                    CustomerSettingTypeId   = 0,
                    IsRequired = false
                };
                RbacEntities.CustomerSettingTypes.Add(settingType);
                RbacEntities.SaveChanges();
            }

            // Does this customer already have one of these settings?
            var setting = RbacEntities.CustomerSettings.FirstOrDefault(customerSetting => customerSetting.CustomerId == customerId &&
                                                                       customerSetting.CustomerSettingTypeId == settingType.CustomerSettingTypeId);

            if (setting == null)
            {
                // Create new customer setting entry
                setting = new CustomerSetting()
                {
                    CustomerId            = customerId,
                    CustomerSettingTypeId = settingType.CustomerSettingTypeId,
                    SettingValue          = settingValue
                };
                RbacEntities.CustomerSettings.Add(setting);
            }
            else
            {
                setting.SettingValue = settingValue;
            }
            RbacEntities.SaveChanges();
        }
Пример #16
0
 /// <summary>
 /// Update an ErrorMessage object in the database
 /// </summary>
 /// <param name="errorCode"></param>
 /// <param name="errorMessage"></param>
 /// <param name="locale"></param>
 /// <param name="errorMessageId"></param>
 /// <param name="active"></param>
 /// <returns></returns>
 public ErrorMessage UpdateErrorMessage(string errorCode, string errorMessage, string locale, int errorMessageId, bool active)
 {
     try
     {
         ErrorMessage message = GetErrorMessageByErrorId(errorMessageId);
         if (message != null)
         {
             message.ErrorCode     = errorCode;
             message.ErrorMessage1 = errorMessage;
             message.Locale        = locale;
             message.Active        = active;
             message.DateModified  = DateTime.Now;
             RbacEntities.SaveChanges();
         }
         return(message);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Пример #17
0
        public int GetPasswordExpirationInDays()
        {
            var username    = WebSecurity.CurrentUserName;
            var userProfile = RbacEntities.UserProfiles.FirstOrDefault(u => u.UserName == username);

            if (userProfile == null)
            {
                return(-1);
            }

            //get the last password change date
            var pwChangeDate = userProfile.Membership.PasswordChangedDate;

            //get when the password expires
            int daysPwValidFor;
            var validForConfig = ConfigurationManager.AppSettings["DaysPWValidFor"];

            int.TryParse(validForConfig, out daysPwValidFor);
            if (daysPwValidFor == 0)
            {
                daysPwValidFor = 90;
            }
            var dayPwExpires = pwChangeDate.Value.AddDays(daysPwValidFor);

            //if it has expires, force them to change it on next login
            if (dayPwExpires.Date <= DateTime.Now.Date)
            {
                //flip the RequirePasswordREseet flag on the user profile

                userProfile.RequirePasswordReset = true;
                RbacEntities.SaveChanges();
            }

            //return the number of days before it expires - the number of days btw now and the expiration date
            TimeSpan expirationTime = dayPwExpires - DateTime.Now;

            return(expirationTime.Days < 0 ? 0 : expirationTime.Days);
        }
Пример #18
0
        /// <summary>
        /// Updates a user's profile
        /// </summary>
        public void UpdateUserProfile(UserModel model, bool isActive)
        {
            var profile = RbacEntities.UserProfiles.FirstOrDefault(u => u.UserName == model.Username);

            if (profile == null)
            {
                return;
            }
            profile.FirstName           = model.FirstName;
            profile.LastName            = model.LastName;
            profile.MiddleName          = model.MiddleInitial;
            profile.Email               = model.EmailAddress;
            profile.Phone               = model.PhoneNumber;
            profile.Membership.IsActive = isActive;
            RbacEntities.SaveChanges();

            //now set the settings that arent a part of the profile(company name, secondary type id and value, etc
            int userID          = GetUserId(model.Username);
            var settingsFactory = new SettingsFactory();

            settingsFactory.Set(userID, Constants.User.OrganizaitonNameField, model.OrganizationName);
            settingsFactory.Set(userID, Constants.User.SecondaryIDType, model.SecondaryIDType);
            settingsFactory.Set(userID, Constants.User.SecondaryIDValue, model.SecondaryIDValue);
        }
        public void SetMaintenanceGroupCustomersModel(int maintGroupId, MaintenanceGroupCustomersModel model)
        {
            // Save any new areas.
            if (model.NewCustomers != null)
            {
                var maintGroup = new PemsCity(maintGroupId.ToString());

                foreach (var newCustomerId in model.NewCustomers)
                {
                    //try to parse the id to make sure it came though correctly
                    int newCustID;
                    var parsed = int.TryParse(newCustomerId, out newCustID);

                    if (parsed)
                    {
                        //now lets check to see if this customer is in the system
                        var existingCustomer = RbacEntities.CustomerProfiles.FirstOrDefault(x => x.CustomerId == newCustID);
                        if (existingCustomer != null)
                        {
                            //only do it if it doesnt exist there already
                            var existing = RbacEntities.MaintenanceGroupCustomers.FirstOrDefault(x => x.MaintenanceGroupId == maintGroupId && x.CustomerId == newCustID);
                            if (existing != null)
                            {
                                continue;
                            }
                            RbacEntities.MaintenanceGroupCustomers.Add(new MaintenanceGroupCustomer
                            {
                                MaintenanceGroupId = maintGroupId,
                                CustomerId         = newCustID
                            });
                            RbacEntities.SaveChanges();

                            //roll thorugh all the ussers for the maint group and if htey are a technician, add them to the _main group for the customer.
                            //This way they will not be member, but will be part of a role so they have access log in to the maint for that cuity

                            //we do not need to roll thorugh the users for the customers, since they are not allowed to assign technicians until they are part of the maintenance group
                            //this means that the customer will not have any technicians, so we do not need to worry about adding those users as techs for the maint group,
                            //that will be done when the user is checked as a tech after the customer is assigned to the maint group.
                            //now add all of the users for this maintenance group that are technicians to the _maintenance role for the customer.

                            //we are also only doing this for new customers.

                            //get all the users for the maintenance group
                            var mainGroupMembersUsernames = (new SecurityManager()).GetUsersForCity(maintGroup.InternalName);

                            //get the customer and an auth manager for that customer
                            var customer             = new PemsCity(existingCustomer.CustomerId.ToString());
                            var authorizationManager = new AuthorizationManager(customer);

                            //check to see if they are a technician
                            foreach (var mainGroupMembersUsername in mainGroupMembersUsernames)
                            {
                                if (TechnicianFactory.IsUserTechnician(mainGroupMembersUsername))
                                {
                                    //if they are, add them to the _maint role for the customer
                                    authorizationManager.AddGroupMember(Constants.Security.DefaultMaintenanceGroupName,
                                                                        mainGroupMembersUsername);

                                    //go get the userid from the name
                                    var userId = (new UserFactory()).GetUserId(mainGroupMembersUsername);

                                    //we also need to update the caching table to give the technician access to see the site
                                    (new UserCustomerAccessManager()).AddCustomerAccess(userId, maintGroupId);
                                }
                            }
                        }
                    }
                }
            }
        }