public IActionResult Post([FromBody] ProductTypeDto productTypeDto) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var productType = Mapper.Map <ProductType>(productTypeDto); if (_productTypeRepository.ProductTypeExists(productType)) { return(StatusCode(500, "ProductType already exists.")); } var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var profile = _accountRepository.GetUserProfile(userId); var createdProductType = _productTypeRepository.CreateProductType(productType, profile.UserProfileId); if (createdProductType == null) { return(StatusCode(500, "A problem happened while handling your request.")); } var createdProductTypeToReturn = Mapper.Map <ProductTypeDto>(createdProductType); return(Created(createdProductTypeToReturn)); } catch (Exception ex) { _logger.LogError($"Failed in Post /ProductTypes: {ex}"); return(StatusCode(500, "A problem happened while handling your request.")); } }
public bool ProductTypeExists(long id) { return(repository.ProductTypeExists(id)); }