public ActionResult findSlotById(long customizedProductId, long slotId, [FromQuery] string unit) { try { FindSlotModelView findSlotModelView = new FindSlotModelView(); findSlotModelView.customizedProductId = customizedProductId; findSlotModelView.slotId = slotId; findSlotModelView.options.unit = unit; GetSlotModelView slotModelView = new core.application.CustomizedProductController().findSlot(findSlotModelView); return(Ok(slotModelView)); } catch (ResourceNotFoundException e) { return(NotFound(new SimpleJSONMessageService(e.Message))); } catch (Exception) { return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR))); } }
/// <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)); }