Esempio n. 1
0
 public SecurityUsersViewModel(UserInformation userInfo, DataRowView selectedItem, string mode)
 {
     _securityUsers            = new SecurityUsersModel();
     _securityUserBll          = new SecurityUsersBll(userInfo);
     this._saveCommand         = new DelegateCommand(this.Save);
     this._closeCommand        = new DelegateCommand(this.Close);
     _selectedItem             = selectedItem;
     SecurityUsers.UserName    = _selectedItem.Row["USER_NAME"].ToString();
     SecurityUsers.FullName    = _selectedItem.Row["FULL_NAME"].ToString();
     SecurityUsers.Designation = _selectedItem.Row["DESIGNATION"].ToString();
     SecurityUsers.Password    = _selectedItem.Row["PASSWORD"].ToString();
     SecurityUsers.IsAdmin     = _selectedItem.Row["IS_ADMIN"].ToBooleanAsString();
     SecurityUsers.Mode        = mode;
     if (mode == "U")
     {
         UserNameIsEnable = true;
         _selectedItem.Row["PASSWORD"] = "******";
         SecurityUsers.Password        = "******";
     }
     else if (mode == "D")
     {
         this.Save();
     }
     _securityUserBll.GetDesignation(SecurityUsers);
     if (_securityUserBll.CheckIsAdminAvailable())
     {
         if (SecurityUsers.IsAdmin == true)
         {
             AdminVisible = Visibility.Visible;
         }
         else
         {
             AdminVisible = Visibility.Collapsed;
         }
     }
     else
     {
         if (_securityUserBll.GetUserRole(SecurityUsers.UserName).ToValueAsString().ToUpper() == "ADMINISTRATOR")
         {
             AdminVisible = Visibility.Visible;
         }
         else
         {
             AdminVisible = Visibility.Collapsed;
         }
     }
 }
Esempio n. 2
0
        public bool GetDesignation(SecurityUsersModel security)
        {
            try
            {
                DataTable dttable = new DataTable();
                //Keep the record when delete the user and maintain delete flag - 17/12/2015
                dttable = ToDataTable((from c in DB.SEC_USER_MASTER.AsEnumerable()
                                       where (c.DELETE_FLAG == false || c.DELETE_FLAG == null)
                                       orderby c.DESIGNATION
                                       select new { c.DESIGNATION }).Distinct().ToList());
                security.Design = dttable.DefaultView;

                return(true);
            }
            catch (Exception ex)
            {
                throw ex.LogException();
            }
        }
Esempio n. 3
0
        public bool UpdateSecurityUsers(SecurityUsersModel user)
        {
            user.Status = "";
            try
            {
                if (user.Mode == "I")
                {
                    bool insert = true;
                    //Keep the record when delete the user and maintain delete flag - 17/12/2015
                    SEC_USER_MASTER secUsers = (from o in DB.SEC_USER_MASTER
                                                where o.USER_NAME == user.UserName &&
                                                (o.DELETE_FLAG == false || o.DELETE_FLAG == null)
                                                select o).FirstOrDefault <SEC_USER_MASTER>();
                    try
                    {
                        if (secUsers != null)
                        {
                            secUsers    = null;
                            user.Status = PDMsg.AlreadyExists("User");
                            return(false);
                        }
                        secUsers = new SEC_USER_MASTER();
                        secUsers = (from o in DB.SEC_USER_MASTER
                                    where o.USER_NAME == user.UserName &&
                                    (o.DELETE_FLAG == true)
                                    select o).FirstOrDefault <SEC_USER_MASTER>();
                        if (secUsers != null)
                        {
                            insert = false;
                            secUsers.DELETE_FLAG = false;
                        }
                        else
                        {
                            secUsers = new SEC_USER_MASTER();
                        }

                        secUsers.USER_NAME   = user.UserName;
                        secUsers.FULL_NAME   = user.FullName;
                        secUsers.DESIGNATION = user.Designation;
                        secUsers.IS_ADMIN    = user.IsAdmin;

                        byte[] salt;
                        secUsers.PASSWORD       = pwdManager.GeneratePasswordHash(user.Password, out salt);
                        secUsers.SALT           = salt;
                        secUsers.FORCE_PASSWORD = false;
                        secUsers.ENTERED_BY     = userInformation.UserName;
                        secUsers.ENTERED_DATE   = userInformation.Dal.ServerDateTime;

                        if (insert == true)
                        {
                            secUsers.ROWID = Guid.NewGuid();
                            DB.SEC_USER_MASTER.InsertOnSubmit(secUsers);
                        }
                        // AssignRolesForUser(user.UserName);
                        DB.SubmitChanges();

                        secUsers    = null;
                        user.Status = PDMsg.SavedSuccessfully;
                        return(true);
                    }
                    catch (System.Data.Linq.ChangeConflictException)
                    {
                        DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);
                        user.Status = PDMsg.SavedSuccessfully;

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        ex.LogException();
                        DB.SEC_USER_MASTER.DeleteOnSubmit(secUsers);
                    }
                }
                else if (user.Mode == "U")
                {
                    SEC_USER_MASTER users = (from o in DB.SEC_USER_MASTER
                                             where o.USER_NAME == user.UserName &&
                                             (o.DELETE_FLAG == false || o.DELETE_FLAG == null)
                                             select o).FirstOrDefault <SEC_USER_MASTER>();
                    try
                    {
                        if (users != null)
                        {
                            users.USER_NAME   = user.UserName;
                            users.FULL_NAME   = user.FullName;
                            users.DESIGNATION = user.Designation;

                            if (user.Password != "!@#$%^&*()")
                            {
                                byte[] salt;
                                users.PASSWORD       = pwdManager.GeneratePasswordHash(user.Password, out salt);
                                users.SALT           = salt;
                                users.FORCE_PASSWORD = false;
                            }
                            users.IS_ADMIN     = user.IsAdmin;
                            users.UPDATED_BY   = userInformation.UserName;
                            users.UPDATED_DATE = userInformation.Dal.ServerDateTime;
                            DB.SubmitChanges();
                            users       = null;
                            user.Status = PDMsg.UpdatedSuccessfully;
                            return(true);
                        }
                    }
                    catch (System.Data.Linq.ChangeConflictException)
                    {
                        DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);
                        user.Status = PDMsg.UpdatedSuccessfully;

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        ex.LogException();
                        DB.SEC_USER_MASTER.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, users);
                    }
                }
                else if (user.Mode == "D")
                {
                    SEC_USER_MASTER users = (from o in DB.SEC_USER_MASTER
                                             where o.USER_NAME == user.UserName
                                             select o).FirstOrDefault <SEC_USER_MASTER>();
                    if (users != null)
                    {
                        //Keep the record when delete the user and maintain delete flag - 17/12/2015
                        users.DELETE_FLAG  = true;
                        users.UPDATED_BY   = userInformation.UserName;
                        users.UPDATED_DATE = DateTime.Now;
                        //DB.SEC_USER_MASTER.DeleteOnSubmit(users);
                        DB.SubmitChanges();
                        users       = null;
                        user.Status = PDMsg.DeletedSuccessfully;
                        List <SEC_USER_ROLES> lstsecuserroles = (from role in DB.SEC_USER_ROLES
                                                                 where
                                                                 role.USER_NAME.ToUpper().Trim() == user.UserName.ToUpper().Trim()
                                                                 select role).ToList <SEC_USER_ROLES>();
                        DB.SEC_USER_ROLES.DeleteAllOnSubmit(lstsecuserroles);
                        DB.SubmitChanges();

                        return(true);
                    }
                    else if (users == null)
                    {
                        user.Status = PDMsg.DoesNotExists("User");
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex.LogException();
            }
            return(true);
        }