Esempio n. 1
0
        public async Task <ActionResult <UserInfoWithHoursWorkedDto> > GetUserTimestampsFromJobsite(string moniker, [FromQuery] TimestampParameters timestampParameters)
        {
            try
            {
                //get current user
                var user = await _userRepository.GetUser(_userAccessor.GetCurrentUsername());

                //find jobsite
                var jobsiteId = await _jobsiteRepository.GetJobsiteIdByMoniker(moniker);

                if (jobsiteId == 0)
                {
                    return(NotFound($"Error: jobsite '{moniker}' not found"));
                }

                //get user's timestamps by jobsite & date
                var filteredTimestamps = await _timestampRepository
                                         .GetTimestampsForJobByUser(user, moniker, timestampParameters);

                //add the timestamps to the user object
                user.Timestamps = filteredTimestamps;

                //Create MetaData
                var metadata = new
                {
                    filteredTimestamps.TotalCount,
                    filteredTimestamps.PageSize,
                    filteredTimestamps.CurrentPage,
                    filteredTimestamps.HasNext,
                    filteredTimestamps.HasPrevious
                };

                //Add metadata to header
                Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));

                return(Ok(_mapper.Map <UserInfoWithHoursWorkedDto>(user)));
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Server Error: Failed to query database."));
            }
        }