Пример #1
0
        public IActionResult DeleteCustomTextMaterialProp(int materialId, Guid propId)
        {
            try
            {
                // Get custom prop and validate type
                CustomMaterialProp prop = CustomMaterialPropService.GetCustomMaterialProp(propId);
                if (prop.Type != PropType.Text)
                {
                    return(HandleBadRequest("The submitted prop is not of the type `text`."));
                }

                // Update material - remove prop
                MaterialsService.UpdateCustomTextMaterialProp(materialId, prop, null);

                // Done!
                return(NoContent());
            }
            catch (CustomPropNotFoundException exception)
            {
                return(HandleResourceNotFoundException(exception));
            }
            catch (MaterialNotFoundException exception)
            {
                return(HandleResourceNotFoundException(exception));
            }
            catch (Exception exception)
            {
                return(HandleUnexpectedException(exception));
            }
        }
Пример #2
0
        public IActionResult SetCustomTextMaterialProp(int materialId, Guid propId, [FromBody] SetCustomTextMaterialPropRequest setCustomTextMaterialPropRequest)
        {
            if (setCustomTextMaterialPropRequest == null ||
                string.IsNullOrWhiteSpace(setCustomTextMaterialPropRequest.Text))
            {
                return(HandleBadRequest("A text to set for the custom material prop has to be provided."));
            }

            try
            {
                // Get custom prop and validate type
                CustomMaterialProp prop = CustomMaterialPropService.GetCustomMaterialProp(propId);
                if (prop.Type != PropType.Text)
                {
                    return(HandleBadRequest("The submitted prop is not of the type `text`."));
                }

                // Update material - set prop
                MaterialsService.UpdateCustomTextMaterialProp(materialId, prop, setCustomTextMaterialPropRequest.Text);

                // Done!
                return(NoContent());
            }
            catch (CustomPropNotFoundException exception)
            {
                return(HandleResourceNotFoundException(exception));
            }
            catch (MaterialNotFoundException exception)
            {
                return(HandleResourceNotFoundException(exception));
            }
            catch (Exception exception)
            {
                return(HandleUnexpectedException(exception));
            }
        }