Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/07/10 01:48:02 (14 years ago)
Author:
dkahn
Message:

#1061 Moved a paging into a dedicated method to prevent redundancy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs

    r4006 r4007  
    245245    public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords) {
    246246      throw new NotImplementedException();
    247     }
     247      totalRecords = 0;
     248      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
     249        // don't test db - throw an exception instead if something wents wrong
     250        // bail out if there are no records
     251        if (0 == (totalRecords = db.HeuristicLabUsers.Count<HeuristicLabUser>())) return new MembershipUserCollection();
     252
     253        MembershipUserCollection userCollection = new MembershipUserCollection();
     254
     255      }
     256    }
     257
    248258
    249259    public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) {
     
    252262
    253263    public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) {
    254       totalRecords = 0;
    255       using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
    256         if (db == null) {
    257           totalRecords = 0;
    258           return new MembershipUserCollection();
    259         }
    260 
    261         // bail out if there are no records
    262         if (0 == (totalRecords = db.HeuristicLabUsers.Count<HeuristicLabUser>())) return new MembershipUserCollection();
    263 
    264         MembershipUserCollection userCollection = new MembershipUserCollection();
    265         int skip = (pageIndex == 0) ? 0 : (pageIndex * pageSize);
    266 
    267         // .OrderBy(usr=>usr.UserName)
     264      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
     265        // orderby u.UserName
    268266        // skipped ordering for now as the default comparator seems to be wrong
    269         foreach (HeuristicLabUser u in db.HeuristicLabUsers.Skip(skip).Take(pageSize)) {
    270           userCollection.Add(u.getMembershipUser(this.Name));
    271         }
    272         return userCollection;
    273       }
    274     }
     267        IQueryable<HeuristicLabUser> users = (from u in db.HeuristicLabUsers select u);
     268        return PagedCollection(users, pageIndex, pageSize, out totalRecords);
     269      }
     270    }
     271
     272    /// <summary>
     273    /// Helper method that takes an IQueriable object and returns a paged part of it
     274    /// </summary>
     275    /// <param name="querySource"></param>
     276    /// <param name="pageIndex"></param>
     277    /// <param name="pageSize"></param>
     278    /// <param name="totalRecords"></param>
     279    /// <returns></returns>
     280    private MembershipUserCollection PagedCollection(IQueryable<HeuristicLabUser> querySource, int pageIndex, int pageSize, out int totalRecords) {
     281      totalRecords = querySource.Count();
     282      MembershipUserCollection userCollection = new MembershipUserCollection();
     283      int skip = (pageIndex == 0) ? 0 : (pageIndex * pageSize);
     284      foreach (HeuristicLabUser u in querySource.Skip(skip).Take(pageSize)) {
     285        userCollection.Add(u.getMembershipUser(this.Name));
     286      }
     287      return userCollection;
     288    }
     289
    275290    /// <summary>
    276291    /// not jet implemented returns 0 as default
Note: See TracChangeset for help on using the changeset viewer.