protected void DataBindUserGridView()
        {
            DAL.User loggedInUser = Utilities.Membership.GetCurrentLoggedInUser();
            string[] roles = Utilities.Membership.GetCurrentLoggedInUserRole();

            List<User> UserList = null;

            var isAdmin = (from r in roles
                           where r.Contains("Administrators")
                           select r);
            var isDeptHead = (from r in roles
                              where r.Contains("DepartmentHeads") || r.Contains("TemporaryDepartmentHeads")
                              select r);
            using (UserManager um = new UserManager())
                if (isAdmin.Count() > 0)
                {
                    UserList = um.GetAllUsers();
                }
                else if (isDeptHead.Count() > 0)
                {
                    UserList = um.FindUsersByCriteria(
                        new UserSearchDTO() { DepartmentID = loggedInUser.DepartmentID });
                }
                else
                {
                    UserList = um.FindUsersByCriteria(
                        new UserSearchDTO() { UserID = loggedInUser.UserID });
                }
            this.UserGridView.DataSource = UserList;
            this.UserGridView.DataBind();
        }
 protected void DataBindBlackListLogGridView(BlackListLogSearchDTO criteria)
 {
     using (UserManager um = new UserManager())
     {
         List<DAL.BlacklistLog> blacklistLogs = um.FindBlacklistLogByCriteria(criteria);
         this.BlackListLogGridView.DataSource = blacklistLogs;
         this.BlackListLogGridView.DataBind();
     }
 }
 protected void LoadUserGridView()
 {
     using (UserManager um = new UserManager())
     {
         List<User> users = um.FindUsersByCriteria(new UserSearchDTO());
         this.UserGridView.DataSource = users;
         this.UserGridView.DataBind();
     }
 }
 protected void DataBindDepartmentDropDownList()
 {
     using (UserManager um = new UserManager())
     {
         List<Department> departments = um.GetAllDepartments();
         this.DepartmentDropDownList.DataSource = departments;
         this.DepartmentDropDownList.DataBind();
         this.DepartmentDropDownList.Items.Insert(0, new ListItem("All Department", "0"));
     }
 }
 protected void DataBindDepartmentDropDownList()
 {
     using (BLL.UserManager um = new BLL.UserManager())
     {
         this.DepartmentDropDownList.DataValueField = "DepartmentID";
         this.DepartmentDropDownList.DataTextField = "Name";
       //  this.DepartmentDropDownList.DataSource = um.GetAllDepartment();
        // this.DepartmentDropDownList.DataBind();
     }
 }
        protected void SearchButton_Click(object sender, EventArgs e)
        {
            // Create filter
            UserSearchDTO criteria = new UserSearchDTO();

            // set filter from ui controls
            criteria.FirstName = this.FirstNameTextBox.Text;
            criteria.LastName = this.LastNameTextBox.Text;
            using (UserManager um = new UserManager())
            {
                // get users by fileter
                List<User> users = um.FindUsersByCriteria(criteria);
                this.UserGridView.DataSource = users;
                this.UserGridView.DataBind();

            }
        }
        protected void CreateUserButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // get the user entered data from textboxes
                string userName = this.UserName.Text.Trim();
                string password = this.Password.Text.Trim();
                string email = this.Email.Text.Trim();
                string firstName = this.Email.Text.Trim();
                string lastName = this.Email.Text.Trim();
                int departmentID = int.Parse(this.DepartmentDropDownList.SelectedValue.ToString());

                // use the business logic to create user account
                try
                {
                    using (BLL.UserManager um = new BLL.UserManager())
                    {
                        // populate the data into object
                        DAL.User user = new DAL.User();
                        user.UserName = userName;
                        user.Password = password;
                        user.Email = email;
                        user.FirstName = firstName;
                        user.LastName = lastName;

                      //  DAL.Department department = um.GetDepartmentByID(departmentID);
                      //  user.Department = department;

                        using (TransactionScope ts = new TransactionScope())
                        {
                            MembershipUser membershipUser = Membership.CreateUser(user.UserName,
                                    user.Password, user.Email);

                        //    um.CreateUser(user);
                        }

                    }
                }
                catch (Exception exception)
                {
                    // if something is wrong, display the error message
                    this.ErrorMessage.Text = exception.Message;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            requisitionManager = new RequisitionManager();
            UserManager u = new UserManager();

            requisitions = requisitionManager.GetAllUnApprovedRequisitionByDepartmentID(1);
            if (requisitions != null)
            {
                GridView1.DataSource = requisitions;
                DataBind();
            }
            if(requisitions.Count == 0)
            {
                Button1.Visible = false;
                Response.Write("No pending requests for approval.");
            }

               // ApproveSingleRequest();
        }
 protected void gvAdjustments_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         int UserID = (int)DataBinder.Eval(e.Row.DataItem, "CreatedBy");
         if (UserID != 0)
         {
             Literal aa = e.Row.FindControl("CreatedByLiteral") as Literal;
             if (aa != null)
             {
                 using (UserManager um = new UserManager())
                 {
                     User user = um.GetUserByID(UserID);
                     if (user != null) aa.Text = user.UserName;
                 }
             }
         }
     }
 }
 protected void UpdateCollectionPointButton_Click(object sender, EventArgs e)
 {
     try
     {
         int departmentID = (int) this.DepartmentDetailView.DataKey.Value;
         DropDownList CollectionPointDropDownList =
             this.DepartmentDetailView.FindControl("CollectionPointDropDownList") as DropDownList;
         using (UserManager um = new UserManager())
         {
             Department department = um.GetDepartmentByID(departmentID);
             department.CollectionPointID = Convert.ToInt32(CollectionPointDropDownList.SelectedValue);
             um.UpdateDepartment(department);
         }
         DataBindDepartmentDetailView();
     }
     catch (Exception exception)
     {
         this.ErrorMessage.Text = exception.Message;
     }
 }
        protected void DataBindUserGridView()
        {
            List<User> UserList = null;

            using (UserManager um = new UserManager())
                if (Utilities.Membership.IsAdmin)
                {
                    UserList = um.GetAllUsers();
                }
                else if (Utilities.Membership.IsDeptHead || Utilities.Membership.IsTempDeptHead)
                {
                    UserList = um.FindUsersByCriteria(
                        new UserSearchDTO() { DepartmentID = Utilities.Membership.LoggedInuser.DepartmentID });
                }
                else
                {
                    UserList = um.FindUsersByCriteria(
                        new UserSearchDTO() { UserID = Utilities.Membership.LoggedInuser.UserID });
                }
            this.UserGridView.DataSource = UserList;
            this.UserGridView.DataBind();
        }
 protected void Populate()
 {
     UserManager um = new UserManager();
     ddlAttentionTo.DataSource = um.GetUserByDepartment(Utilities.Membership.GetCurrentLoggedInUser().DepartmentID);
     DataBind();
     using (CatalogManager cm = new CatalogManager())
     {
         List<Stationery> stationeries = cm.GetStationeriesByQuantityInHandLessThanReorderLevel();
         this.gvPOItems.DataSource = stationeries;
         this.gvPOItems.DataBind();
     }
     lblCreatedBy.Text = Membership.GetCurrentLoggedInUser().UserName;
     lblDate.Text = DateTime.Now.ToShortDateString();
 }
 public static User GetCurrentLoggedInUser()
 {
     WebSecurity.MembershipUser membershipUser = WebSecurity.Membership.GetUser();
     if (membershipUser != null)
     {
         using (UserManager userManager = new UserManager())
         {
             List<User> users =
                 userManager.FindUsersByCriteria(
                     new UserSearchDTO() { UserName = membershipUser.UserName });
             if (users.Count > 0)
                 return users[0];
             else
             {
                 throw new Exceptions.UserException("No current logged in user.");
             }
         }
     }
     else
     {
         throw new Exceptions.UserException("No current logged in user.");
     }
 }
 public static List<DAL.User> FindUsersByCriteria(DAL.DTO.UserSearchDTO criteria)
 {
     using (BLL.UserManager um = new UserManager())
     {
         return um.FindUsersByCriteria(criteria);
     }
 }
        private void Populate()
        {
            if (Request.QueryString["ID"] != "")
            {
                int adjID = int.Parse(Request.QueryString["ID"]);
                using (AdjustmentVoucherManager avm = new AdjustmentVoucherManager())
                {
                    AdjustmentVoucher tran = avm.FindAdjustmentVoucherByID(adjID);
                    this.gvAdjustmentItems.DataSource = tran.StockLogs.ToList<StockLog>();
                    this.gvAdjustmentItems.DataBind();

                    lblVoucherNumber.Text = tran.VoucherNumber;
                    lblIssueDate.Text = tran.DateIssued.ToShortDateString();
                    using (UserManager um = new UserManager())
                    {
                        User u = um.GetUserByID(tran.CreatedBy);
                        lblCreatedBy.Text = u.UserName;
                    }
                    decimal totalCost = avm.GetTotalCostVoucher(tran);
                    lblCost.Text = String.Format("{0:C}", totalCost);
                }
            }
        }