public IActionResult UpdateMaterialMasterData(int id, [FromBody] MaterialUpdateRequest materialUpdateRequest) { if (materialUpdateRequest == null || string.IsNullOrWhiteSpace(materialUpdateRequest.Name) || string.IsNullOrWhiteSpace(materialUpdateRequest.Manufacturer) || string.IsNullOrWhiteSpace(materialUpdateRequest.ManufacturerId) || string.IsNullOrWhiteSpace(materialUpdateRequest.Type)) { return(HandleBadRequest("Incomplete or invalid material data submitted for update.")); } // Check for material type validity Plastic plastic = null; try { plastic = PlasticsService.GetPlastic(materialUpdateRequest.Type); } catch (PlasticNotFoundException exception) { return(HandleBadRequest(exception.Message)); } // Proceed with updating try { Material material = MaterialsService.UpdateMaterial(id, materialUpdateRequest.Name, materialUpdateRequest.Manufacturer, materialUpdateRequest.ManufacturerId, plastic); return(Ok(material)); } catch (MaterialNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (Exception exception) { return(HandleUnexpectedException(exception)); } }