Example #1
0
        public async Task <IActionResult> Create([FromBody] ProfessionCreateDTO professionDTO)
        {
            var location = GetControllerActionNames();

            try
            {
                _logger.LogInfo($"{location}: Create Attempted");
                if (professionDTO == null)
                {
                    _logger.LogWarn($"{location}: Empty Request was submitted");
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogWarn($"{location}: Data was Incomplete");
                    return(BadRequest(ModelState));
                }
                var profession = _mapper.Map <Profession>(professionDTO);
                var isSuccess  = await _professionRepository.Create(profession);

                if (!isSuccess)
                {
                    return(InternalError($"{location}: Creation failed"));
                }
                _logger.LogInfo($"{location}: Creation was successful");
                return(Created("Create", new { profession }));
            }
            catch (Exception e)
            {
                return(InternalError($"{location}: {e.Message} - {e.InnerException}"));
            }
        }