public IEnumerable<gift_categories> GetGiftCategories() { var context = new appsterEntities(); try { var data = context.gift_categories.ToArray(); return data; } finally { context.Dispose(); } }
public IEnumerable<user> GetUsersByPage(Func<user, bool> predicate, bool loadBack, int take, int page, out PagingHelper pagingInfo) { var context = new appsterEntities(); try { var totalItems = context.users.Count(predicate); pagingInfo = PagingHelper.GetPageInfo(totalItems, page, take); var skip = pagingInfo.CurentPage == 0 ? 0 : (pagingInfo.CurentPage - 1) * take; if (loadBack) { var data = (from users in context.users.Where(predicate) orderby users.id descending select users).Skip(skip).Take(pagingInfo.Count).ToList(); return data; } else { var data = (from users in context.users.Where(predicate) select users).Skip(skip).Take(pagingInfo.Count).ToList(); return data; } } finally { context.Dispose(); } }
public IEnumerable<dynamic> GetSavePushNotifications(Func<save_push_notifications, bool> predicate, int take) { var context = new appsterEntities(); context.Configuration.AutoDetectChangesEnabled = false; try { var data = context.save_push_notifications.Where(predicate).OrderByDescending(n => n.id) .Join(context.users, p => p.resiver_user_id, u => u.id, (p, u) => new { Id = p.id, UserId = p.user_id, ReceiverId = p.resiver_user_id, ReceiverName = u.display_name, Message = p.message, CreatedDate = p.created }).Take(take).ToArray(); return data; } finally { context.Configuration.AutoDetectChangesEnabled = true; context.Dispose(); } }
public async Task<dynamic> GetUserAdditionalInformation(int userId) { var context = new appsterEntities(); try { var followings = context.follows.Count(i => i.id == userId); var followers = context.follows.Count(i => i.follow_user_id == userId); var posts = context.posts.Count(i => i.user_id == userId); return new { FollowerCount = followers, FollowingCount = followings, PostCount = posts }; } finally { context.Dispose(); } }
public IEnumerable<Models.gift> GetGifts(Func<Models.gift, bool> predicate, int take, int cursor = 0, bool loadBack = false) { var context = new appsterEntities(); context.Configuration.AutoDetectChangesEnabled = false; try { var data = loadBack ? (from gifts in context.gifts.Where(predicate).OrderByDescending(i => i.id) where cursor == 0 || gifts.id < cursor select gifts).Take(take).ToArray() : (from gifts in context.gifts.Where(predicate) where gifts.id > cursor select gifts).Take(take).ToArray(); return data; } finally { context.Configuration.AutoDetectChangesEnabled = true; context.Dispose(); } }