public ActionResult deleteSlot(long customizedProductId, long slotId, [FromHeader(Name = "UserToken")] string userAuthToken) { try { DeleteSlotModelView deleteSlotModelView = new DeleteSlotModelView(); deleteSlotModelView.customizedProductId = customizedProductId; deleteSlotModelView.slotId = slotId; new core.application.CustomizedProductController().deleteSlot(deleteSlotModelView); return(NoContent()); } 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> /// Deletes a slot from a CustomizedProduct. /// </summary> /// <param name="deleteSlotModelView">Instance of DeleteSlotModelView containing both the CustomizedProduct's and Slot's identifiers.</param> /// <exception cref="ResourceNotFoundException">Thrown when either no CustomizedProduct or Slot could be found with the given identifiers.</exception> public void deleteSlot(DeleteSlotModelView deleteSlotModelView) { CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories().createCustomizedProductRepository(); CustomizedProduct customizedProduct = customizedProductRepository.find(deleteSlotModelView.customizedProductId); if (customizedProduct == null) { throw new ResourceNotFoundException( string.Format(ERROR_UNABLE_TO_FIND_CUSTOMIZED_PRODUCT_BY_ID, deleteSlotModelView.customizedProductId) ); } checkUserToken(customizedProduct, deleteSlotModelView.userAuthToken); Slot slot = customizedProduct.slots.Where(s => s.Id == deleteSlotModelView.slotId).SingleOrDefault(); if (slot == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_SLOT, deleteSlotModelView.slotId)); } customizedProduct.removeSlot(slot); customizedProductRepository.update(customizedProduct); }