public virtual async Task <MoodleGradebookColumn> CreateColumnAsync(string title, float maximumScore, string tag = null) { // Title must not be null if (title == null) { throw new ArgumentNullException(nameof(title)); } // Score must be positive if (maximumScore < 0) { throw new ArgumentOutOfRangeException(nameof(maximumScore), "The maximum score must not be negative."); } // Create line item var lineItem = new MoodleLtiLineItem { Label = title, ResourceLinkId = _resourceLinkId, ScoreMaximum = maximumScore, Tag = tag }; int id = await _ltiApi.CreateLineItemAsync(lineItem); // Retrieve and return created line item var createdLineItem = await _ltiApi.GetLineItemAsync(id); return(new MoodleGradebookColumn(createdLineItem)); }
public Task UpdateLineItemAsync(MoodleLtiLineItem lineItem) { if (!_lineItems.ContainsKey(lineItem.Id)) { throw new MoodleLtiException(nameof(UpdateLineItemAsync)); } var lid = _lineItems[lineItem.Id]; lid.LineItem = lineItem.Clone(); return(Task.CompletedTask); }
public async Task UpdateLineItemAsync(MoodleLtiLineItem lineItem) { // Build URL string url = $"{_serviceUrl}/lineitems/{lineItem.Id}/lineitem?{_queryStringPrefix}"; // Serialize line item lineItem.StringId = url; string serializedLineItem = JsonConvert.SerializeObject(lineItem, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); await DoPutRequestAsync(url, serializedLineItem, "application/vnd.ims.lis.v2.lineitem+json", new[] { HttpStatusCode.OK }); }
public async Task <int> CreateLineItemAsync(MoodleLtiLineItem lineItem) { // Build URL string url = $"{_serviceUrl}/lineitems?{_queryStringPrefix}"; // Serialize line item string serializedLineItem = JsonConvert.SerializeObject(lineItem, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); (string responseBody, HttpStatusCode _) = await DoPostRequestAsync(url, serializedLineItem, "application/vnd.ims.lis.v2.lineitem+json", new[] { HttpStatusCode.Created }); // Try to deserialize result MoodleLtiLineItem resultLineItem = JsonConvert.DeserializeObject <MoodleLtiLineItem>(responseBody); // Extract ID return(GetNumericLineItemId(resultLineItem.StringId)); }
public Task <int> CreateLineItemAsync(MoodleLtiLineItem lineItem) { LineItemData lineItemData = new LineItemData { LineItem = new MoodleLtiLineItem { Id = _nextLineItemId++, Label = lineItem.Label, LtiLinkId = lineItem.LtiLinkId, ResourceId = lineItem.ResourceId, ResourceLinkId = lineItem.ResourceLinkId, ScoreMaximum = lineItem.ScoreMaximum, Tag = lineItem.Tag }, Scores = new Dictionary <string, MoodleLtiScore>() }; _lineItems.Add(lineItemData.LineItem.Id, lineItemData); return(Task.FromResult(lineItemData.LineItem.Id)); }