public static User FindByUserName(this DBEntities DB, string userName) { return(DB.Users.Where(u => u.UserName == userName).FirstOrDefault()); }
public static List <BookmarkView> BookmarkList(this DBEntities DB, User viewer, string SortBy, bool ascendant) { List <BookmarkView> bookmarkItems = new List <BookmarkView>(); foreach (Bookmark bookmark in DB.Bookmarks) { bookmarkItems.Add(new BookmarkView { Id = bookmark.Id, Name = bookmark.Name, Shared = bookmark.Shared, OwnerId = bookmark.UserId, OwnerName = bookmark.User.FirstName + " " + bookmark.User.LastName, CategoryName = bookmark.Category == null ? "" : bookmark.Category.Name, Url = bookmark.Url }); } switch (SortBy) { case "Name": if (ascendant) { bookmarkItems = bookmarkItems.OrderBy(b => b.Name).ToList(); } else { bookmarkItems = bookmarkItems.OrderByDescending(b => b.Name).ToList(); } break; case "Url": if (ascendant) { bookmarkItems = bookmarkItems.OrderBy(b => b.Url).ToList(); } else { bookmarkItems = bookmarkItems.OrderByDescending(b => b.Url).ToList(); } break; case "OwnerName": if (ascendant) { var temp = bookmarkItems; bookmarkItems = bookmarkItems.Where(x => x.Shared).ToList(); bookmarkItems.AddRange(temp.OrderBy(b => b.OwnerName).Where(x => x.Shared == false).ToList()); } else { var temp = bookmarkItems; bookmarkItems = (bookmarkItems.OrderByDescending(b => b.OwnerName).Where(x => x.Shared == false).ToList()); bookmarkItems.AddRange(temp.Where(x => x.Shared).ToList()); } break; case "Category": if (ascendant) { bookmarkItems = bookmarkItems.OrderBy(b => b.CategoryName).ToList(); } else { bookmarkItems = bookmarkItems.OrderByDescending(b => b.CategoryName).ToList(); } break; } return(bookmarkItems); }