public async Task <List <PostDto> > GetPostsAsync(bool IsJob = true, bool IsProject = true) { List <PostDto> list = new List <PostDto>(); var filterBuilder = Builders <Post> .Filter; var filter = IsJob && IsProject?((filterBuilder.Eq(x => x.PostType, PostTypes.Job) | filterBuilder.Eq(x => x.PostType, PostTypes.Project))) :(IsJob? filterBuilder.Eq(x => x.PostType, PostTypes.Job): filterBuilder.Eq(x => x.PostType, PostTypes.Project)); await Context1.Find(filter) .SortByDescending(post => post.Date).ForEachAsync(post => list.Add(new PostDto() { Id = post.Id, Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, AccountId = post.AccountId, PostType = post.PostType, AccountName = post.AccountName, AccountType = post.AccountType, Availabilty = post.Availabilty, Categories = post.Categories, Comments = post.Comments, Descreption = post.Descreption, Hours = post.Hours, KindPay = post.KindPay, Likes = post.Likes, Region = post.Region, Sallaries = post.Sallaries, Skills = post.Skills, Specifications = post.Specifications })); return(list); }
public async Task <List <PostMiniDto> > GetPostsMiniAsync() { List <PostMiniDto> list = new List <PostMiniDto>(); await Context1.Find(post => true).SortByDescending(post => post.Date).ForEachAsync(post => list.Add(new PostMiniDto() { Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, Comments = post.Comments.HierarchyCount(), Likes = post.Likes.LongCount(), Descreption = post.Descreption, Id = post.Id })); return(list); return(await Context1.AsQueryable().Select(post => new PostMiniDto() { Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, Comments = post.Comments.HierarchyCount(), Likes = post.Likes.LongCount(), Descreption = post.Descreption, Id = post.Id }).ToListAsync()); }
public async Task <object> GetSimplesAsync() { //will throw eception until pass true or MongoDBRepository<SimpleModel,Foo> , Foo should inherent BaeEntity //var data = await Context<Foo>(true).AsQueryable().ToListAsync(); // create and use fine , out of MongoDBRepository<SimpleModel> var data = await Context <Foo>(true).AsQueryable().ToListAsync(); await Seed(); // two way to use // await Context<SimpleModel>().Find(s => true).ToListAsync(); return(await Context1.Find(s => true).ToListAsync()); }
public async Task <PostMiniDto> GetPostByIdMiniAsync(string id) { var post = await Context1.Find(post => post.Id == id).SingleOrDefaultAsync <Post>(); return(new PostMiniDto() { Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, Likes = post.Likes.LongCount(), Descreption = post.Descreption, Id = post.Id, Comments = post.Comments.LongCount(), }); }
public async Task <List <PostDto> > GetPostsFilterAsync(FilterDto filter) { List <PostDto> list = new List <PostDto>(); var filterBuilder = Builders <Post> .Filter; var exfilter = filterBuilder.Eq(x => x.PostType, PostTypes.Job); var exfilterd = (filterBuilder.Eq(x => x.Title, filter.Title) | filterBuilder.ElemMatch(x => x.Tags, filter.Tag) | filterBuilder.Eq(x => x.Region, filter.Region) | filterBuilder.ElemMatch(x => x.Specifications, filter.Specification) | filterBuilder.Eq(x => x.Sallaries, new MinMax(filter.Min, filter.Max)) | filterBuilder.Eq(x => x.Availabilty, filter.Availabilty)); await Context1.Find(exfilter) .SortByDescending(post => post.Date).ForEachAsync(post => list.Add(new PostDto() { Id = post.Id, Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, AccountId = post.AccountId, PostType = post.PostType, AccountName = post.AccountName, AccountType = post.AccountType, Availabilty = post.Availabilty, Categories = post.Categories, Comments = post.Comments, Descreption = post.Descreption, Hours = post.Hours, KindPay = post.KindPay, Likes = post.Likes, Region = post.Region, Sallaries = post.Sallaries, Skills = post.Skills, Specifications = post.Specifications })); list = list.Where(x => x.Availabilty == filter.Availabilty && x.Title.Contains(filter.Title ?? "")).ToList(); return(list); }