public async Task <IActionResult> Create([FromBody] CreateMaterialResource resource) { var material = _mapper.Map <CreateMaterialResource, Material>(resource); var result = await _materials.CreateAsync(material); if (!result.Success) { foreach (var keyValuePair in result.Messages) { if (keyValuePair.Key.StartsWith("Dublicate")) { return(Conflict(new ErrorResource(result.Messages))); } } return(BadRequest(new ErrorResource(result.Messages))); } var materialResource = _mapper.Map <Material, MaterialResource>(result.Resource); return(Ok(materialResource)); }