public async Task <ActionResult <TaskUserWorkingHoursRecord> > CreateRecord([FromBody] CreateWorkingHoursRecordDto creationDto)
        {
            if (!Request.Headers.TryGetValue(_requestIdHeaderName, out StringValues requestIdValue))
            {
                return(BadRequest($"{_requestIdHeaderName} header must be specified!"));
            }

            string requestId = requestIdValue.ToString();

            try
            {
                TaskUserWorkingHoursRecord newRecord = _mapper.Map <CreateWorkingHoursRecordDto, TaskUserWorkingHoursRecord>(creationDto);
                var createdRecord = await _workingHoursService.CreateRecordAsync(newRecord, requestId);

                return(Ok(createdRecord));
            }
            catch (AlreadyHandledException e)
            {
                return(Accepted(e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest($"{e.GetType()} : {e.Message}"));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult <MemberWorkingHoursAggregate> > CreateRecord([FromBody] CreateWorkingHoursRecordDto creationDto)
        {
            if (!Request.Headers.TryGetValue(Constants.RequestIdHeaderName, out StringValues requestIdValue))
            {
                return(BadRequest($"{Constants.RequestIdHeaderName} header must be specified!"));
            }

            if (!Request.Headers.TryGetValue(Constants.UserIdHeaderName, out StringValues userIdValue))
            {
                return(BadRequest($"{Constants.UserIdHeaderName} header must be specified!"));
            }

            string requestId = requestIdValue.ToString();
            string userId    = userIdValue.ToString();

            try
            {
                TaskUserWorkingHoursRecord newRecord = _mapper.Map <CreateWorkingHoursRecordDto, TaskUserWorkingHoursRecord>(creationDto);
                newRecord.UserId = userId;

                var createdRecord = await _workingHoursService.CreateRecordAsync(newRecord, requestId);

                return(Ok(createdRecord));
            }
            catch (AlreadyHandledException ahe)
            {
                return(Accepted(ahe.Message));
            }
            catch (NotFoundException nfe)
            {
                return(NotFound(nfe.Message));
            }
            catch (Exception e)
            {
                return(BadRequest($"{e.GetType()} : {e.Message}"));
            }
        }