Ejemplo n.º 1
0
        public async Task <IActionResult> GetGoalsAsync(DateTimeOffset?startDate = null, DateTimeOffset?endDate = null, bool?showCompleted = null)
        {
            if (!Guid.TryParse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value, out Guid userId))
            {
                return(Unauthorized());
            }

            var getGoalsCreatedByUserQuery = new GetGoalsCreatedByUserQuery()
            {
                CreatedBy = userId, StartDate = startDate, EndDate = endDate, ShowCompleted = showCompleted
            };
            var goals = await _mediator.Send(getGoalsCreatedByUserQuery);

            Response.AddPaginationMetadata(goals);

            return(Ok(goals));
        }
Ejemplo n.º 2
0
        public async Task <PagedList <GoalDto> > Handle(GetGoalsCreatedByUserQuery query, CancellationToken cancellationToken)
        {
            using var connection = new SqlConnection(_connectionStringProvider.ConnectionString);
            connection.Open();

            var sqlQuery = sql;

            if (query.StartDate.HasValue && query.EndDate.HasValue)
            {
                sqlQuery += $@" and (@Start <= g.AimDate_End and g.AimDate_Start <= @End)";
            }

            if (!query.ShowCompleted.HasValue || !query.ShowCompleted.Value)
            {
                sqlQuery += $@" and (g.GoalStatusId = {GoalStatus.ToDo.Id})";
            }

            return((await connection.QueryAsync <GoalDto>(sqlQuery, new { UserId = query.CreatedBy, Start = query.StartDate, End = query.EndDate })).ToPagedList(query.PageNumber, query.PageSize));
        }