Exemplo n.º 1
0
        public async Task <IActionResult> GetOneJobAsync(
            [FromRoute, SwaggerParameter("Id of the job to receive")] Guid jobId,
            [FromQuery, SwaggerParameter("Request which fields you want returned")] string fields,
            [FromHeader(Name = "Accept"), SwaggerParameter("Request Hateoas")] string mediaType)
        {
            if (!string.IsNullOrWhiteSpace(fields))
            {
                if (!_typeHelperService.TypeHasProperties <JobDto>(fields))
                {
                    return(BadRequest());
                }
            }

            var foundJob = await _jobRepository.GetFirstByConditionAsync(j => j.Id == jobId);

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

            var job = Mapper.Map <JobDto>(foundJob);

            var shapedEmployeeJob = job.ShapeData(fields);

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

            return(Ok(shapedEmployeeJob));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetOneScheduleAsync(
            [FromRoute, SwaggerParameter("Id of the employee to find schedule of", Required = true)] Guid employeeId,
            [FromRoute, SwaggerParameter("Id of the schedule to find", Required = true)] Guid scheduleId,
            [FromQuery, SwaggerParameter("Request which fields you want returned")] string fields,
            [FromHeader(Name = "accept"), SwaggerParameter("Request Hateoas")] string mediaType)
        {
            if (!string.IsNullOrWhiteSpace(fields) && !_typeHelperService.TypeHasProperties <ScheduleDto>(fields))
            {
                return(BadRequest());
            }

            if (!await _scheduleRepository.EntityExists <Employee>(e => e.Id == employeeId))
            {
                return(NotFound());
            }

            var foundSchedule = await _scheduleRepository.GetFirstByConditionAsync(j => j.Id == scheduleId);

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

            var mappedSchedule = Mapper.Map <ScheduleDto>(foundSchedule);

            var shapedSchedule = mappedSchedule.ShapeData(fields);

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

            return(Ok(shapedSchedule));
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> GetEmployeeJobAsync(
            [FromRoute, SwaggerParameter("Id of the employee to find job by", Required = true)] Guid employeeId,
            [FromQuery, SwaggerParameter("Request which fields you want returned")] string fields,
            [FromHeader(Name = "Accept"), SwaggerParameter("Request Hateoas")] string mediaType)
        {
            if (!string.IsNullOrWhiteSpace(fields))
            {
                if (!_typeHelperService.TypeHasProperties <JobDto>(fields))
                {
                    return(BadRequest());
                }
            }

            if (!await _jobRepository.EntityExists <Employee>(e => e.Id == employeeId))
            {
                return(NotFound());
            }

            var foundEmployeeJob = await _jobRepository.GetJobByEmployeeId(employeeId);

            var emplooyeJob = Mapper.Map <JobDto>(foundEmployeeJob);

            var shapedEmployeeJob = emplooyeJob.ShapeData(fields);

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

            return(Ok(shapedEmployeeJob));
        }