Exemple #1
0
        public async Task <IActionResult> GetOneWorkhoursAsync(
            [FromRoute, SwaggerParameter("Id of employee to find", Required = true)] Guid employeeId,
            [FromRoute, SwaggerParameter("Id of workhours to find", Required = true)] Guid workhoursId,
            [FromQuery, SwaggerParameter("Request which fields you want returned")] string fields,
            [FromHeader(Name = "accept"), SwaggerParameter("Request Hateoas")] string mediaType)
        {
            if (!await _workhoursRepository.EntityExists <Employee>(e => e.Id == employeeId))
            {
                return(NotFound());
            }

            var foundWorkhours = await _workhoursRepository.GetFirstByConditionAsync(j => j.Id == workhoursId);

            if (foundWorkhours == null)
            {
                return(NotFound());
            }

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

            var shapedWorkhours = workhoursToReturn.ShapeData(fields);

            if (mediaType == "application/vnd.AO.json+hateoas")
            {
                ((IDictionary <string, object>)shapedWorkhours).Add("links", _controllerHelper.CreateLinksForResource(foundWorkhours.Id, fields, "Workhours"));
            }

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

            var foundWorkhours = await _workhoursRepository.GetFirstByConditionAsync(j => j.Id == workhoursId);

            if (foundWorkhours == null)
            {
                return(NotFound());
            }

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

            return(Ok(workhoursToReturn));
        }