/// <summary> /// Converts an instance of CustomizedProduct into an instance of GetCustomizedProductModelView. /// </summary> /// <param name="customizedProduct">Instance of CustomizedProduct being converted.</param> /// <param name="unit">String representing the unit to which the CustomizedProduct's dimensions will be converted to.</param> /// <returns>Instance of GetCustomizedProductModelView.</returns> /// <exception cref="System.ArgumentException">Thrown when the provided instance of CustomizedProduct is null.</exception> public static GetCustomizedProductModelView fromEntity(CustomizedProduct customizedProduct, string unit) { if (customizedProduct == null) { throw new ArgumentException(ERROR_NULL_CUSTOMIZED_PRODUCT); } GetCustomizedProductModelView customizedProductModelView = new GetCustomizedProductModelView(); customizedProductModelView.customizedProductId = customizedProduct.Id; customizedProductModelView.reference = customizedProduct.reference; customizedProductModelView.designation = customizedProduct.designation; customizedProductModelView.status = customizedProduct.status; customizedProductModelView.customizedDimensions = CustomizedDimensionsModelViewService.fromEntity(customizedProduct.customizedDimensions, unit); if (customizedProduct.customizedMaterial != null) { customizedProductModelView.customizedMaterial = CustomizedMaterialModelViewService.fromEntity(customizedProduct.customizedMaterial); } customizedProductModelView.product = ProductModelViewService.fromEntityAsBasic(customizedProduct.product); customizedProductModelView.slots = SlotModelViewService.fromCollection(customizedProduct.slots, unit); return(customizedProductModelView); }
/// <summary> /// Retrieves an instance of Slot associated to an instance of CustomizedProduct. /// </summary> /// <param name="findSlotModelView">Instance of FindSlotModelView containing the CustomizedProduct's and the Slot's persistence identifiers.</param> /// <returns>Instance of GetSlotModelView containing Slot information.</returns> /// <exception cref="ResourceNotFoundException">Thrown when the either the CustomizedProduct or the Slot could not be found.</exception> public GetSlotModelView findSlot(FindSlotModelView findSlotModelView) { CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories().createCustomizedProductRepository(); CustomizedProduct customizedProduct = customizedProductRepository.find(findSlotModelView.customizedProductId); if (customizedProduct == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_CUSTOMIZED_PRODUCT_BY_ID, findSlotModelView.customizedProductId)); } Slot slot = customizedProduct.slots.Where(s => s.Id == findSlotModelView.slotId).SingleOrDefault(); if (slot == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_SLOT, findSlotModelView.slotId)); } return(SlotModelViewService.fromEntity(slot, findSlotModelView.options.unit)); }