public ActionResult <MaterialDTO> addMaterial([FromBody] MaterialDTO materialDTO) { try { MaterialDTO createdMaterialDTO = new core.application.MaterialsController().addMaterial(materialDTO); if (createdMaterialDTO != null) { return(CreatedAtRoute("GetMaterial", new { id = createdMaterialDTO.id }, createdMaterialDTO)); } else { return(BadRequest(new SimpleJSONMessageService(UNABLE_TO_ADD_MATERIAL))); } } catch (NullReferenceException) { return(BadRequest(new SimpleJSONMessageService(INVALID_REQUEST_BODY_MESSAGE))); } catch (ArgumentException argumentException) { return(BadRequest(new SimpleJSONMessageService(argumentException.Message))); } catch (Exception) { return(StatusCode(500, UNEXPECTED_ERROR)); } }
public ActionResult <MaterialDTO> findById(long id, [FromQuery] bool pricedFinishesOnly) { try { MaterialDTO materialDTO = new core.application.MaterialsController().findMaterialByID(id, pricedFinishesOnly); if (materialDTO == null) { return(BadRequest(new SimpleJSONMessageService(MATERIAL_NOT_FOUND))); } return(Ok(materialDTO)); } catch (ResourceNotFoundException e) { return(NotFound(new SimpleJSONMessageService(e.Message))); } catch (NullReferenceException e) { return(BadRequest(new SimpleJSONMessageService(e.Message))); } catch (Exception) { return(StatusCode(500, UNEXPECTED_ERROR)); } }
public ActionResult <List <MaterialDTO> > findAll() { try { List <MaterialDTO> materials = new core.application.MaterialsController().findAllMaterials(); if (Collections.isListEmpty(materials)) { return(NotFound(new SimpleJSONMessageService(NO_MATERIALS_FOUND))); } return(Ok(materials)); } catch (Exception) { return(StatusCode(500, UNEXPECTED_ERROR)); } }
public ActionResult addColor(long idMaterial, [FromBody] ColorDTO addColorDTO) { try { AddColorModelView addColorModelView = new core.application.MaterialsController().addColor(idMaterial, addColorDTO); if (addColorModelView != null) { return(Created(Request.Path, addColorModelView)); } } catch (NullReferenceException) { return(BadRequest(new SimpleJSONMessageService(INVALID_REQUEST_BODY_MESSAGE))); } catch (Exception) { return(StatusCode(500, UNEXPECTED_ERROR)); } return(BadRequest(new SimpleJSONMessageService(UNABLE_TO_UPDATE_MATERIAL))); }