public IActionResult CreatePreference([FromBody] PreferenceForCreationDto preference) { try { if (preference == null) { _logger.LogError("Preference object sent from client is null."); return(BadRequest("Preference object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid Preference object sent from client."); return(BadRequest("Invalid model object")); } bool succes = _preferenceLogic.Create(preference); return(Ok("Preference is created")); } catch (Exception ex) { return(StatusCode(500, "Internal server error")); } }
public bool Create(PreferenceForCreationDto preferenceForCreation) { try { Preference DataEntity = _mapper.Map <Preference>(preferenceForCreation); _repository.Create(DataEntity); _repository.Save(); return(true); } catch (Exception ex) { _logger.LogError($"Something went wrong inside CreatePreference action: {ex.Message}"); throw new Exception(); } }