public async Task <IActionResult> Put(SupplierDto supplierDto, int id) { try { if (id == 0) { return(BadRequest("Id cannot be 0")); } Supplier temp = new Supplier(supplierDto); bool hasOverwritten = await _putService.PutAsync(temp, id); IEnumerable <Supplier> result = await _getService.GetAsync(id); if (hasOverwritten) { return(Ok(result.FirstOrDefault())); } return(CreatedAtAction( nameof(Put), id, result.FirstOrDefault())); } catch (Exception exception) { _exceptionLogger.LogException(exception, nameof(SuppliersController), _logger); throw; } }
public async Task <IActionResult> Put(ProductDto productDto, int id) { try { if (id == 0) { return(BadRequest("Id cannot be 0")); } await _validationService.EnsureValidDependencies(productDto); Product temp = new Product(productDto, _context); bool hasOverwritten = await _putService.PutAsync(temp, id); IEnumerable <Product> result = await _getService.GetAsync(id); if (hasOverwritten) { return(Ok(result.FirstOrDefault())); } return(CreatedAtAction( nameof(Put), id, result.FirstOrDefault())); } catch (EntityNotFoundException notFoundException) { return(BadRequest(notFoundException.Message)); } catch (Exception exception) { _exceptionLogger.LogException(exception, nameof(UnitsController), _logger); throw; } }