public ActionResult <IEnumerable <Class> > GetAllClasses() { var filters = new FiltersDto { Subject = Request.Query["subject"].ToString(), WeekDay = Request.Query["weekDay"].ToString(), Time = Request.Query["time"].ToString() }; var classes = new List <ClassReadDto>(); foreach (var item in _classRepository.GetAllClasses(filters)) { var user = _userRepository.GetUserById(item.UserId); var classInfo = new ClassReadDto { UserId = user.Id, Name = user.Name, AvatarUrl = user.AvatarUrl, Bio = user.Bio, WhatsApp = user.WhatsApp, Subject = item.Subject, Cost = item.Cost }; classes.Add(classInfo); } return(Ok(classes)); }
public FiltersDto GetFilters() { FiltersDto filtersDto = new FiltersDto(); filtersDto.Items = dataContext.Items.Select(item => new FilterItemDto() { Id = item.Id, ItemName = item.ItemName }).ToList(); filtersDto.SearchTypes = new SearchType[] { SearchType.WantItem, SearchType.HaveItem }; return(filtersDto); }
public IEnumerable <MaterialDto> GetInfoWithFilters(FiltersDto dto) { if (Enum.IsDefined(typeof(Categories), dto.category) == false) { throw new WrongCategoryException("Wrong category. Use: Presentation, App, Other"); } if (dto.minSize < 0 || dto.maxSize < 0) { throw new WrongMaterialSizeException("Wrong material size. The minimum and maximum material " + "size must be greater than -1."); } return(CastToMaterialDtos(_dbService.GetMaterialsByNameAndSizes(dto.category, dto.minSize, dto.maxSize))); }
public async Task <IEnumerable <PostForDisplayDto> > GetPostsForUserAsync(FiltersDto filter, string username) { string orderQuery = GetOrderQuery(filter.Filter, filter.Order); string startingDate = GetStartDate(filter.Period); var query = this._client. Cypher .Match("(post:Post)") .Where($"post.CreatedAt>=datetime('{startingDate}')") .Match("(post)-[r:CreatedBy]-(creator:User)") .Match($"(user:User)") .Where((User user) => user.Username == username) .With("post,creator,user") .OptionalMatch($"(post)-[:tagged]-(tag:Tag)") .With("post,creator,user,tag") .OptionalMatch("()-[c:Comment]->(post)") .With("post,creator,user,tag,count(c) as CommentNo") .OptionalMatch("()-[agr:Choice {Opinion: \"agree\"}]->(post)") .With("post,creator,user,tag,CommentNo,count(agr) as agrNo") .OptionalMatch("()-[dagr:Choice {Opinion: \"disagree\"}]->(post)") .With("id(post) as id,post,creator,user,tag,CommentNo,agrNo, count(dagr) as dagrNo") .OptionalMatch("(user)-[choice:Choice]-(post)") .With("id(post) as id,post,creator,user,tag,CommentNo,agrNo,dagrNo,choice, Exists((user)-[:Follow]-(post)) as follow") .Return((post, creator, tag, id, CommentNo, agrNo, dagrNo, choice, follow) => new PostForDisplayDto { Id = id.As <long>(), Text = post.As <Post>().Text, Creator = creator.As <User>().Username, Title = post.As <Post>().Title, Tags = tag.CollectAsDistinct <Tag>(), CreatedAt = post.As <Post>().CreatedAt, Choice = choice.As <Choice>().Opinion, ImageUrls = post.As <Post>().ImageUrls, CommentNo = CommentNo.As <int>(), AgreeNo = (int)agrNo.As <int>(), DisagreeNo = (int)dagrNo.As <int>(), Follow = follow.As <bool>() }) .OrderBy(orderQuery) .Skip(filter.Page * filter.Limit) .Limit(filter.Limit); var results = await query.ResultsAsync; return(results); }
public async Task <IActionResult> GetPostsCreatedBy([FromForm] FiltersDto filter, string createdBy) { var identity = HttpContext.User.Identity as ClaimsIdentity; IEnumerable <Claim> claim = identity.Claims; var usernameClaim = claim .Where(x => x.Type == ClaimTypes.Name) .FirstOrDefault(); IEnumerable <PostForDisplayDto> posts; if (usernameClaim != null) { posts = await _rep.GetPostsCreatedByForUserAsync(filter, createdBy, usernameClaim.Value); } else { posts = await _rep.GetPostsCreatedByAsync(filter, createdBy); } return(Ok(posts)); }
public IEnumerable <Class> GetAllClasses(FiltersDto filters) { IQueryable <Class> query = _dbContext.Classes.Include(c => c.Schedules); if (filters.Subject != string.Empty) { query = query.Where(w => w.Subject == filters.Subject); } if (filters.WeekDay != string.Empty) { query = query.Where(w => w.Schedules.Any(e => e.ClassId == w.Id && e.WeekDay == Convert.ToInt32(filters.WeekDay))); } if (filters.Time != string.Empty) { var minutes = new StringToMinutesConversor().Convert(filters.Time); query = query.Where(w => w.Schedules.Any(e => e.ClassId == w.Id && e.From <= minutes)); } return(query.ToList()); }