Esempio n. 1
0
    protected bool FillAndFilterEntity(LocalUserEntity ent, String keyword)
    {
        if (ent == null)
        {
            return(true);
        }

        if (!String.IsNullOrWhiteSpace(keyword) &&
            (cbUserName.Checked ||
             cbPassword.Checked ||
             cbFirstNameFilter.Checked ||
             cbLastNameFilter.Checked ||
             cbEmail.Checked ||
             cbAddress.Checked))
        {
            var flag = (cbUserName.Checked && !String.IsNullOrWhiteSpace(ent.LoginName) && ent.LoginName.Contains(keyword)) ||
                       (cbPassword.Checked && !String.IsNullOrWhiteSpace(ent.Password) && ent.Password.Contains(keyword)) ||
                       (cbFirstNameFilter.Checked && !String.IsNullOrWhiteSpace(ent.FirstName) && ent.FirstName.Contains(keyword)) ||
                       (cbLastNameFilter.Checked && !String.IsNullOrWhiteSpace(ent.LastName) && ent.LastName.Contains(keyword)) ||
                       (cbEmail.Checked && !String.IsNullOrWhiteSpace(ent.Email) && ent.Email == keyword) ||
                       (cbAddress.Checked && !String.IsNullOrWhiteSpace(ent.Address) && ent.Address.Contains(keyword));


            return(flag);
        }

        return(true);
    }
Esempio n. 2
0
    protected IEnumerable <LocalUserEntity> LoadUsers(String status, Guid?categoryID)
    {
        var usersQuery = (from n in DataContext.UM_Users
                          where n.DateDeleted == null
                          select n);

        if (status != "-1" && categoryID == Guid.Empty)
        {
            usersQuery = (from n in usersQuery
                          where n.IsActive == bool.Parse(status)
                          select n);
        }
        else if (status != "-1" && categoryID != Guid.Empty)
        {
            usersQuery = (from n in usersQuery
                          where n.IsActive == bool.Parse(status) &&
                          n.UserCategoryID == categoryID
                          select n);
        }
        else if (categoryID != Guid.Empty && status == "-1")
        {
            usersQuery = (from n in usersQuery
                          where n.UserCategoryID == categoryID
                          select n);
        }

        var userCategoriesQuery = (from n in usersQuery
                                   where n.UserCategory != null
                                   select n.UserCategory).Distinct();

        var userCategoriesDict = userCategoriesQuery.ToDictionary(n => n.ID);

        var userList = usersQuery.ToList();

        foreach (var user in userList)
        {
            var entity = new LocalUserEntity
            {
                ID                     = user.ID,
                DateChanged            = user.DateChanged,
                DateCreated            = user.DateCreated,
                DateDeleted            = user.DateDeleted,
                LoginName              = user.LoginName,
                Password               = user.Password,
                FirstName              = user.FirstName,
                LastName               = user.LastName,
                Email                  = user.Email,
                Address                = user.Address,
                IsActive               = user.IsActive,
                UserCategoryID         = user.UserCategoryID,
                PasswordExpirationDate = user.PasswordExpirationDate,
            };

            var userCat = userCategoriesDict.GetValueOrDefault(user.UserCategoryID.GetValueOrDefault());
            if (userCat != null)
            {
                entity.UserCategoryName = userCat.Name;
            }

            yield return(entity);
        }
    }