public ActionResult addSlotToCustomizedProduct(long id, [FromBody] AddCustomizedDimensionsModelView slotDimensions, [FromHeader(Name = "UserToken")] string userAuthToken) { if (slotDimensions == null) { return(BadRequest(new SimpleJSONMessageService(INVALID_REQUEST_BODY_MESSAGE))); } try { AddSlotModelView addSlotModelView = new AddSlotModelView(); addSlotModelView.customizedProductId = id; addSlotModelView.slotDimensions = slotDimensions; addSlotModelView.userAuthToken = userAuthToken; GetCustomizedProductModelView customizedProductModelView = new core.application.CustomizedProductController().addSlotToCustomizedProduct(addSlotModelView); return(Created(Request.Path, customizedProductModelView)); } catch (ResourceNotFoundException e) { return(NotFound(new SimpleJSONMessageService(e.Message))); } catch (NotAuthorizedException notAuthorizedException) { return(StatusCode(401, new SimpleJSONMessageService(notAuthorizedException.Message))); } catch (ArgumentException e) { return(BadRequest(new SimpleJSONMessageService(e.Message))); } catch (InvalidOperationException e) { return(BadRequest(new SimpleJSONMessageService(e.Message))); } catch (Exception) { return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR))); } }
/// <summary> /// Adds a Slot to a CustomizedProduct. /// </summary> /// <param name="addSlotModelView">AddSlotModelView with the Slot's information</param> /// <returns>An instance of GetCustomizedProductModelView containing updated CustomizedProduct information.</returns> /// <exception cref="ResourceNotFoundException">Thrown when the CustomizedProduct could not be found.</exception> public GetCustomizedProductModelView addSlotToCustomizedProduct(AddSlotModelView addSlotModelView) { CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories().createCustomizedProductRepository(); CustomizedProduct customizedProduct = customizedProductRepository.find(addSlotModelView.customizedProductId); if (customizedProduct == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_CUSTOMIZED_PRODUCT_BY_ID, addSlotModelView.customizedProductId)); } checkUserToken(customizedProduct, addSlotModelView.userAuthToken); CustomizedDimensions customizedDimensions = CustomizedDimensionsModelViewService.fromModelView(addSlotModelView.slotDimensions); customizedProduct.addSlot(customizedDimensions); customizedProduct = customizedProductRepository.update(customizedProduct); return(CustomizedProductModelViewService.fromEntity(customizedProduct)); }