public ActionResult updateSlot(long customizedProductId, long slotId, [FromBody] UpdateSlotModelView updateSlotModelView, [FromHeader(Name = "UserToken")] string userAuthToken) { if (updateSlotModelView == null) { return(BadRequest(new SimpleJSONMessageService(INVALID_REQUEST_BODY_MESSAGE))); } try { updateSlotModelView.customizedProductId = customizedProductId; updateSlotModelView.slotId = slotId; GetCustomizedProductModelView customizedProductModelView = new core.application.CustomizedProductController().updateSlot(updateSlotModelView); return(Ok(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> /// Updates an instance of Slot. /// </summary> /// <param name="updateSlotModelView">Instance of UpdateSlotModelView.</param> /// <returns>Instance of GetCustomizedProductModelView with updated CustomizedProduct information.</returns> /// <exception cref="ResourceNotFoundException">Thrown when the CustomizedProduct or the Slot could not be found.</exception> /// <exception cref="System.ArgumentException">Thrown when none of the CustomizedProduct's properties are updated.</exception> public GetCustomizedProductModelView updateSlot(UpdateSlotModelView updateSlotModelView) { CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories().createCustomizedProductRepository(); CustomizedProduct customizedProduct = customizedProductRepository.find(updateSlotModelView.customizedProductId); if (customizedProduct == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_CUSTOMIZED_PRODUCT_BY_ID, updateSlotModelView.customizedProductId)); } checkUserToken(customizedProduct, updateSlotModelView.userAuthToken); Slot slot = customizedProduct.slots.Where(s => s.Id == updateSlotModelView.slotId).SingleOrDefault(); if (slot == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_SLOT, updateSlotModelView.slotId)); } bool performedAtLeastOneUpdate = false; if (updateSlotModelView.dimensions != null) { CustomizedDimensions updatedDimensions = CustomizedDimensionsModelViewService.fromModelView(updateSlotModelView.dimensions); customizedProduct.resizeSlot(slot, updatedDimensions); performedAtLeastOneUpdate = true; } if (!performedAtLeastOneUpdate) { throw new ArgumentException(ERROR_NO_UPDATE_PERFORMED); } customizedProduct = customizedProductRepository.update(customizedProduct); return(CustomizedProductModelViewService.fromEntity(customizedProduct)); }