/// <summary> /// Retrieves an instance of CustomizedProduct. /// </summary> /// <param name="findCustomizedProductModelView">Instance of FindCustomizedProductModelView containing the CustomizedProduct's identifier.</param> /// <returns>Instance of GetCustomizedProductModelView containing CustomizedProduct information.</returns> /// <exception cref="ResourceNotFoundException">Thrown when no CustomizedProduct could be found with the given identifier.</exception> public GetCustomizedProductModelView findCustomizedProduct(FindCustomizedProductModelView findCustomizedProductModelView) { CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories().createCustomizedProductRepository(); CustomizedProduct customizedProduct = customizedProductRepository.find(findCustomizedProductModelView.customizedProductId); if (customizedProduct == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_CUSTOMIZED_PRODUCT_BY_ID, findCustomizedProductModelView.customizedProductId)); } return(CustomizedProductModelViewService.fromEntity(customizedProduct, findCustomizedProductModelView.options.unit)); }
public ActionResult getRecommendedSlots(long customizedProductId, [FromQuery] string unit) { try { FindCustomizedProductModelView findCustomizedProductModelView = new FindCustomizedProductModelView(); findCustomizedProductModelView.customizedProductId = customizedProductId; findCustomizedProductModelView.options.unit = unit; GetAllCustomizedDimensionsModelView allCustomDimensionsMV = new core.application.CustomizedProductController().getRecommendedSlots(findCustomizedProductModelView); return(Ok(allCustomDimensionsMV)); } catch (ResourceNotFoundException ex) { return(NotFound(new SimpleJSONMessageService(ex.Message))); } catch (Exception) { return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR))); } }
/// <summary> /// Gets min slots from a certain customized product /// </summary> /// <param name="findCustomizedProductModelView">Instance of FindCustomizedProductModelView.</param> /// <exception cref="ResourceNotFoundException">Thrown when no CustomizedProduct could be found with the given identifier.</exception> /// <returns>Instance of GetAllCustomizedDimensionsModelView representing the minimum Slots.</returns> public GetAllCustomizedDimensionsModelView getMinSlots(FindCustomizedProductModelView findCustomizedProductModelView) { CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories().createCustomizedProductRepository(); CustomizedProduct customizedProduct = customizedProductRepository.find(findCustomizedProductModelView.customizedProductId); if (customizedProduct == null) { throw new ResourceNotFoundException( string.Format(ERROR_UNABLE_TO_FIND_CUSTOMIZED_PRODUCT_BY_ID, findCustomizedProductModelView.customizedProductId) ); } List <CustomizedDimensions> customizedDimensions = customizedProduct.minSlots(); return(CustomizedDimensionsModelViewService.fromCollection(customizedDimensions, findCustomizedProductModelView.options.unit)); }
public ActionResult findByID(long id, [FromQuery] string unit) { try { FindCustomizedProductModelView findCustomizedProductModelView = new FindCustomizedProductModelView(); findCustomizedProductModelView.customizedProductId = id; findCustomizedProductModelView.options.unit = unit; GetCustomizedProductModelView fetchedCustomizedProduct = new core.application.CustomizedProductController().findCustomizedProduct(findCustomizedProductModelView); return(Ok(fetchedCustomizedProduct)); } catch (ResourceNotFoundException e) { return(NotFound(new SimpleJSONMessageService(e.Message))); } catch (InvalidOperationException e) { return(BadRequest(new SimpleJSONMessageService(e.Message))); } catch (Exception) { return(NotFound(new SimpleJSONMessageService(UNEXPECTED_ERROR))); } }