Beispiel #1
0
        public ActionResult <SingleRecordDto> CreateRecord([FromBody, Required] RecordForCreationDto record)
        {
            try
            {
                var recordEntity = _mapper.Map <Record>(record);

                if (!_recordsRepository.EmployeeExists(recordEntity.EmployeeId))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden));
                }

                if (_recordsRepository.RecordExists(recordEntity.Id))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden));
                }

                _recordsRepository.AddRecord(recordEntity);

                var recordToReturn = _mapper.Map <SingleRecordDto>(recordEntity);
                return(CreatedAtRoute("GetRecordv2",
                                      new
                {
                    recordId = recordToReturn.Id
                },
                                      recordToReturn));
            }
            catch
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public ActionResult <IEnumerable <RecordDto> > GetRecordsForEmployee(string employeeId)
        {
            try
            {
                if (!_recordsRepository.EmployeeExists(employeeId))
                {
                    return(NotFound());
                }

                var allRecordsForEmployee = _recordsRepository.GetRecordsForEmployee(employeeId);

                return(Ok(_mapper.Map <IEnumerable <RecordDto> >(allRecordsForEmployee)));
            }
            catch
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Beispiel #3
0
        public ActionResult <EmployeeDto> GetEmployee(string employeeId)
        {
            try
            {
                if (!_recordsRepository.EmployeeExists(employeeId))
                {
                    return(NotFound());
                }

                var employee = _recordsRepository.GetEmployee(employeeId);

                return(Ok(_mapper.Map <EmployeeDto>(employee)));
            }
            catch
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }