public IActionResult CreateCustomMaterialProp([FromBody] CustomMaterialPropCreationRequest customMaterialPropCreationRequest)
        {
            if (customMaterialPropCreationRequest == null ||
                string.IsNullOrWhiteSpace(customMaterialPropCreationRequest.Name))
            {
                return(HandleBadRequest("Missing prop data: a name and type are required."));
            }

            // Attempt to parse type
            PropType type;

            if (Enum.IsDefined(typeof(PropType), customMaterialPropCreationRequest.Type))
            {
                type = (PropType)customMaterialPropCreationRequest.Type;
            }
            else
            {
                return(HandleBadRequest("A valid prop type needs to be provided."));
            }

            // Attempt to create
            try
            {
                CustomMaterialProp prop = CustomMaterialPropService.CreateCustomMaterialProp(customMaterialPropCreationRequest.Name, type);
                return(Created(GetNewResourceUri(prop.Id), prop));
            }
            catch (Exception exception)
            {
                return(HandleUnexpectedException(exception));
            }
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MaterialsController"/> class.
 /// </summary>
 /// <param name="loggerFactory">A factory to create loggers from.</param>
 /// <param name="plasticsService">Grants access to known plastics.</param>
 /// <param name="materialsService">The materials service.</param>
 /// <param name="customMaterialPropService">Grants access to custom material props.</param>
 public MaterialsController(ILoggerFactory loggerFactory,
                            PlasticsService plasticsService,
                            MaterialsService materialsService,
                            CustomMaterialPropService customMaterialPropService)
 {
     Logger                    = loggerFactory.CreateLogger <MaterialsController>();
     PlasticsService           = plasticsService;
     MaterialsService          = materialsService;
     CustomMaterialPropService = customMaterialPropService;
 }
 /// <summary>
 /// Initializes the controller.
 /// </summary>
 /// <param name="loggerFactory">Factory to create loggers from.</param>
 /// <param name="configurationService">The service that provides configuration functionality.</param>
 /// <param name="customPropService">The service providing custom material prop functionality.</param>
 /// <param name="customBatchPropService">The service providing custom batch prop functionality.</param>
 public ConfigurationController(ILoggerFactory loggerFactory,
                                ConfigurationService configurationService,
                                CustomMaterialPropService customPropService,
                                CustomBatchPropService customBatchPropService)
 {
     Logger = loggerFactory.CreateLogger <ConfigurationController>();
     ConfigurationService      = configurationService;
     CustomMaterialPropService = customPropService;
     CustomBatchPropService    = customBatchPropService;
 }
 public IActionResult GetCustomMaterialProps()
 {
     try
     {
         return(Ok(CustomMaterialPropService.GetAllCustomMaterialProps()));
     }
     catch (Exception exception)
     {
         return(HandleUnexpectedException(exception));
     }
 }
        public IActionResult UpdateCustomMaterialProp(Guid id, [FromBody] CustomMaterialPropUpdateRequest customMaterialPropUpdateRequest)
        {
            if (customMaterialPropUpdateRequest == null ||
                string.IsNullOrWhiteSpace(customMaterialPropUpdateRequest.Name))
            {
                return(HandleBadRequest("A valid prop name needs tu be supplied."));
            }

            try
            {
                CustomMaterialProp prop = CustomMaterialPropService.UpdateCustomMaterialProp(id, customMaterialPropUpdateRequest.Name);
                return(Ok(prop));
            }
            catch (CustomPropNotFoundException exception)
            {
                return(HandleResourceNotFoundException(exception));
            }
            catch (Exception exception)
            {
                return(HandleUnexpectedException(exception));
            }
        }
 public IActionResult DeleteCustomMaterialProp(Guid id)
 {
     CustomMaterialPropService.DeleteCustomMaterialProp(id);
     return(NoContent());
 }