Skip to content

Commit

Permalink
Fixed bug where a NRE would be thrown if no homework was available
Browse files Browse the repository at this point in the history
  • Loading branch information
GitWither committed Jun 13, 2020
1 parent b301497 commit 64a31fb
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions classeviva-net/Classeviva.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,24 @@ public async Task<Homework[]> GetHomeworkAsync(DateTime startDate, DateTime endD
startDate.Subtract(new DateTime(1970, 1, 1)).TotalSeconds.ToString() + "&end=" +
endDate.Subtract(new DateTime(1970, 1, 1)).TotalSeconds.ToString());
HomeworkBody[] homeworkBody = JsonConvert.DeserializeObject<HomeworkBody[]>(await msg.Content.ReadAsStringAsync());
Homework[] homework = new Homework[ homeworkBody.Length ];
for (int i = 0; i < homeworkBody.Length; i++)
if (homeworkBody != null)
{
homework[ i ] = new Homework(
homeworkBody[ i ].id,
homeworkBody[ i ].title,
DateTime.ParseExact(homeworkBody[ i ].start, "yyyy-MM-dd HH:mm:ss", null),
DateTime.ParseExact(homeworkBody[ i ].end, "yyyy-MM-dd HH:mm:ss", null),
homeworkBody[ i ].allDay,
DateTime.ParseExact(homeworkBody[ i ].data_inserimento, "dd-MM-yyyy HH:mm:ss", null),
homeworkBody[ i ].autore_desc,
homeworkBody[ i ].nota_2);
Homework[] homework = new Homework[homeworkBody.Length];
for (int i = 0; i < homeworkBody.Length; i++)
{
homework[i] = new Homework(
homeworkBody[i].id,
homeworkBody[i].title,
DateTime.ParseExact(homeworkBody[i].start, "yyyy-MM-dd HH:mm:ss", null),
DateTime.ParseExact(homeworkBody[i].end, "yyyy-MM-dd HH:mm:ss", null),
homeworkBody[i].allDay,
DateTime.ParseExact(homeworkBody[i].data_inserimento, "dd-MM-yyyy HH:mm:ss", null),
homeworkBody[i].autore_desc,
homeworkBody[i].nota_2);
}
return homework;
}
return homework;
else return null;
}
}
}

0 comments on commit 64a31fb

Please sign in to comment.