SIMS 7 - Lesson Attendance changes Summer 24 code sample
The purpose of this article is to show the improved 3rd party API attendance model which supports the planned 1/8/24 changes to attendance from the DfE.
Please note that the APIs now expect LessonAttendanceExtended
Lesson class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace SIMSAttendanceDemo.DataClasses
{
// using System.Xml.Serialization;
// XmlSerializer serializer = new XmlSerializer(typeof(LessonAttendancesExtended));
// using (StringReader reader = new StringReader(xml))
// {
// var test = (LessonAttendancesExtended)serializer.Deserialize(reader);
// }
[XmlRoot(ElementName = "LessonAttendanceExtended")]
public class LessonAttendanceExtended
{
[XmlElement(ElementName = "PersonID")]
public int? PersonID { get; set; }
[XmlElement(ElementName = "BaseGroupID")]
public int BaseGroupID { get; set; }
[XmlElement(ElementName = "AttendanceDate")]
public DateTime AttendanceDate { get; set; }
[XmlElement(ElementName = "AttendancePeriod")]
public string AttendancePeriod { get; set; }
[XmlElement(ElementName = "EmployeeID")]
public int? EmployeeID { get; set; }
[XmlElement(ElementName = "LocationID")]
public int? LocationID { get; set; }
[XmlElement(ElementName = "EventInstanceID")]
public int EventInstanceID { get; set; }
[XmlElement(ElementName = "AttendanceMark")]
public string AttendanceMark { get; set; }
[XmlElement(ElementName = "Minute")]
public int? Minute { get; set; }
[XmlElement(ElementName = "Comments")]
public string Comments { get; set; }
[XmlElement(ElementName = "StatutoryComment")]
public string StatutoryComment { get; set; }
}
[XmlRoot(ElementName = "LessonAttendancesExtended")]
public class LessonAttendancesExtended
{
[XmlElement(ElementName = "LessonAttendanceExtended")]
public List<LessonAttendanceExtended> LessonAttendanceExtended { get; set; }
}
}
The read marks and save marks would expect the same structure.
Get a set of attendance marks
private static List<DataClasses.LessonAttendanceExtended> GetPersonLessonMarks()
{
List<DataClasses.LessonAttendanceExtended> les = new List<DataClasses.LessonAttendanceExtended>();
string Les = TPAR.GetXmlLessonAttendancesExtendedV3(StudentId, AcademicClassId, (DateTime)StartDate, (DateTime)EndDate);
XmlSerializer serializer = new XmlSerializer(typeof(DataClasses.LessonAttendancesExtended));
using (StringReader reader = new StringReader(Les))
{
DataClasses.LessonAttendancesExtended test = (DataClasses.LessonAttendancesExtended)serializer.Deserialize(reader);
les = test.LessonAttendanceExtended;
}
return les;
}
Then update them, firstly to a B code without a statutory explanation which fails to save, followed by the setting of a statutory explanation and successful save.
if (TPAR == null)
{
TPAR = new SIMS.Processes.TPAttendanceRead();
TPAW = new SIMS.Processes.TPAttendanceWrite();
}
SetIds();
SetCodes();
List<DataClasses.LessonAttendanceExtended> person_lessons = GetPersonLessonMarks();
foreach (DataClasses.LessonAttendanceExtended mark in person_lessons)
{
mark.AttendanceMark = "B";
}
if (!LessonMarkSaveTest(person_lessons)) // SHould fail without a stat exp.
{
DumpErrors();
foreach (DataClasses.LessonAttendanceExtended m in person_lessons)
{
m.StatutoryComment = "Testing"; // Provide the required stat exp.
}
if (LessonMarkSaveTest(person_lessons)) // SHould save.
{
Console.WriteLine("Correct Save");
}
else
{
DumpErrors();
Console.WriteLine("Failed to Save");
}
}
else
{
Console.WriteLine("Incorrect Save");
}
}