public ActionResult createMinimumSlots(long customizedProductId, [FromQuery] string unit, [FromHeader(Name = "UserToken")] string userAuthToken) { try { AddSlotLayoutModelView addSlotLayoutModelView = new AddSlotLayoutModelView(); addSlotLayoutModelView.customizedProductId = customizedProductId; addSlotLayoutModelView.userAuthToken = userAuthToken; addSlotLayoutModelView.options.unit = unit; GetCustomizedProductModelView customizedProductModelView = new core.application.CustomizedProductController().addMinimumSlots(addSlotLayoutModelView); return(Ok(customizedProductModelView)); } catch (ResourceNotFoundException e) { return(NotFound(new SimpleJSONMessageService(e.Message))); } catch (NotAuthorizedException notAuthorizedException) { return(StatusCode(401, new SimpleJSONMessageService(notAuthorizedException.Message))); } catch (InvalidOperationException e) { return(BadRequest(new SimpleJSONMessageService(e.Message))); } catch (Exception) { return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR))); } }
/// <summary> /// Adds the minimum slot layout to the CustomizedProduct with the given persistence identifier. /// </summary> /// <param name="addSlotLayoutModelView">Instance of AddSlotLayoutModelView.</param> /// <exception cref="ResourceNotFoundException">Thrown when no CustomizedProduct could be found with the given identifier.</exception> /// <returns>Instance of GetCustomizedProductModelView with the recommended Slot layout.</returns> public GetCustomizedProductModelView addMinimumSlots(AddSlotLayoutModelView addSlotLayoutModelView) { CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories().createCustomizedProductRepository(); CustomizedProduct customizedProduct = customizedProductRepository.find(addSlotLayoutModelView.customizedProductId); if (customizedProduct == null) { throw new ResourceNotFoundException( string.Format(ERROR_UNABLE_TO_FIND_CUSTOMIZED_PRODUCT_BY_ID, addSlotLayoutModelView.customizedProductId) ); } checkUserToken(customizedProduct, addSlotLayoutModelView.userAuthToken); customizedProduct.addMinimumSlots(); customizedProduct = customizedProductRepository.update(customizedProduct); return(CustomizedProductModelViewService.fromEntity(customizedProduct, addSlotLayoutModelView.options.unit)); }