예제 #1
0
        public async Task <IActionResult> GetAllWorkhourssAsync(
            [FromRoute] Guid employeeId,
            [FromQuery] RequestParameters request,
            [FromHeader(Name = "accept")] string mediaType)
        {
            if (!await _workhoursRepository.EntityExists <Employee>(e => e.Id == employeeId))
            {
                return(NotFound());
            }

            var foundWorkhours = await _workhoursRepository.GetAllByConditionAsync(s => s.EmployeeId == employeeId);

            var workhoursToReturn = Mapper.Map <IEnumerable <WorkhoursDto> >(foundWorkhours);

            var shapedWorkhours = workhoursToReturn.ShapeData(request.Fields);

            if (mediaType == "application/vnd.AO.json+hateoas")
            {
                var shapedAndLinkedWorkhours = _controllerHelper.AddLinksToShapedObjects(shapedWorkhours, "Workhours", request.Fields);

                var linkedResourceCollection = _controllerHelper.AddLinksToCollection(shapedAndLinkedWorkhours, request, false, false, "Workhours");

                return(Ok(linkedResourceCollection));
            }
            return(Ok(shapedWorkhours));
        }
예제 #2
0
        public async Task <IActionResult> GetAllWorkhourssAsync([FromRoute] Guid employeeId)
        {
            if (!await _workhoursRepository.EntityExists <Employee>(e => e.Id == employeeId))
            {
                return(NotFound());
            }

            var foundWorkhours = await _workhoursRepository.GetAllByConditionAsync(s => s.EmployeeId == employeeId);

            var workhoursToReturn = Mapper.Map <IEnumerable <WorkhoursDto> >(foundWorkhours);

            return(Ok(workhoursToReturn));
        }