Esempio n. 1
0
        public async Task <IActionResult> Create([FromBody] CustomerCreateDTO CustomerDTO)
        {
            var location = GetControllerActionNames();

            try
            {
                _logger.LogInfo($"{location}: Create Attempted");
                if (CustomerDTO == null)
                {
                    _logger.LogWarn($"{location}: Empty Request was submitted");
                    return(BadRequest(ModelState));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogWarn($"{location}: Data was Incomplete");
                    return(BadRequest(ModelState));
                }

                var customer = _mapper.Map <Customer>(CustomerDTO);
                var result   = await _businessLogic.Add(customer);

                if (result.IsFailed)
                {
                    return(InternalError($"{location}: Creation failed"));
                }

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