Skip to content

Commit b7b998d

Browse files
committed
Made PersonList sometimes immutable.
1 parent c22c138 commit b7b998d

19 files changed

+85
-72
lines changed

bin/MataSharp.dll

0 Bytes
Binary file not shown.

src/MataSharp/Assignment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public partial class Assignment : IComparable<Assignment>
1414
public uint? Grade { get; set; }
1515
public string Class { get; set; }
1616
public ReadOnlyCollection<Attachment> Attachments { get; set; }
17-
public PersonList<MagisterPerson> Teachers { get; set; }
17+
public PersonList Teachers { get; set; }
1818
public int ID { get; set; }
1919
public DateTime HandInTime { get; set; }
2020
public DateTime DeadLine { get; set; }
@@ -138,7 +138,7 @@ public Assignment toAssignment()
138138
{
139139
Grade = this.Beoordeling,
140140
Attachments = this.Bijlagen.ToList(AttachmentType.Assignment_teacher),
141-
Teachers = this.Docenten.ToList(true),
141+
Teachers = this.Docenten.ToList(true, true),
142142
ID = this.Id,
143143
HandInTime = this.IngeleverdOp.ToDateTime(),
144144
DeadLine = this.InleverenVoor.ToDateTime(),

src/MataSharp/Extensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,15 @@ internal static ReadOnlyCollection<Attachment> ToList(this Attachment[] currentA
8585
#endregion
8686

8787
#region PersonList
88-
internal static PersonList<MagisterPerson> ToList(this IEnumerable<MagisterStylePerson> collection, bool download, Mata mata = null)
88+
internal static PersonList ToList(this IEnumerable<MagisterStylePerson> collection, bool download,bool ReadOnly = false, Mata mata = null)
8989
{
9090
var tmpMata = mata ?? _Session.Mata;
91-
return new PersonList<MagisterPerson>(tmpMata, collection, download);
91+
return new PersonList(tmpMata, collection,ReadOnly, download);
9292
}
9393

94-
public static PersonList<MagisterPerson> ToList(this IEnumerable<MagisterPerson> collection, Mata mata = null)
94+
public static PersonList ToList(this IEnumerable<MagisterPerson> collection, Mata mata = null)
9595
{
96-
var tmpMata = mata ?? _Session.Mata;
97-
return new PersonList<MagisterPerson>(tmpMata, collection);
96+
return new PersonList(collection, mata);
9897
}
9998
#endregion
10099
}

src/MataSharp/Homework.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public bool Done
2222
_Session.HttpClient.Put(this.URL(), JsonConvert.SerializeObject(this.ToMagisterStyle()));
2323
}
2424
}
25-
public PersonList<MagisterPerson> Teachers { get; set; }
25+
public PersonList Teachers { get; set; }
2626
public DateTime End { get; set; }
2727
public int ID { get; set; }
2828
internal int InfoType;
@@ -132,11 +132,11 @@ public Homework ToHomework()
132132
{
133133
Notes = this.AantekeningLeerling,
134134
_Done = this.Afgerond,
135-
Teachers = this.Docenten.ToList(true),
135+
Teachers = this.Docenten.ToList(true, true),
136136
End = this.Einde.ToDateTime(),
137137
ID = this.Id,
138138
InfoType = this.InfoType,
139-
Content = this.Inhoud,
139+
Content = this.Inhoud.Trim(),
140140
EndBySchoolHour = this.LesuurTM,
141141
BeginBySchoolHour = this.LesuurVan,
142142
Location = this.Lokatie,

src/MataSharp/MagisterMessage.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public partial class MagisterMessage : IComparable<MagisterMessage>, ICloneable
1616
public string Subject { get; set; }
1717
public MagisterPerson Sender { get; internal set; }
1818
public string Body { get; set; }
19-
public PersonList<MagisterPerson> Recipients { get; set; }
20-
public PersonList<MagisterPerson> CC { get; set; }
19+
public PersonList Recipients { get; set; }
20+
public PersonList CC { get; set; }
2121
public DateTime SentDate { get; set; }
2222
internal bool _IsRead;
2323

@@ -86,8 +86,8 @@ public MagisterMessage()
8686
this.IDKey = 0;
8787
this.SenderGroupID = this.Mata.Person.GroupID;
8888
this.Sender = this.Mata.Person;
89-
this.Recipients = new PersonList<MagisterPerson>(this.Mata);
90-
this.CC = new PersonList<MagisterPerson>(this.Mata);
89+
this.Recipients = new PersonList(this.Mata);
90+
this.CC = new PersonList(this.Mata);
9191
}
9292

9393
/// <summary>
@@ -112,8 +112,8 @@ public MagisterMessage(Mata Mata)
112112
this.IDKey = 0;
113113
this.SenderGroupID = this.Mata.Person.GroupID;
114114
this.Sender = this.Mata.Person;
115-
this.Recipients = new PersonList<MagisterPerson>(this.Mata);
116-
this.CC = new PersonList<MagisterPerson>(this.Mata);
115+
this.Recipients = new PersonList(this.Mata);
116+
this.CC = new PersonList(this.Mata);
117117
}
118118

119119
/// <summary>
@@ -140,7 +140,7 @@ public MagisterMessage CreateForwardMessage()
140140
Deleted = false,
141141
_IsRead = true,
142142
Subject = tmpSubject,
143-
Recipients = new PersonList<MagisterPerson>(this.Mata),
143+
Recipients = new PersonList(this.Mata),
144144
Ref = null,
145145
State = 0,
146146
SentDate = DateTime.UtcNow,
@@ -172,7 +172,7 @@ public MagisterMessage CreateForwardMessage(string ContentAdd)
172172
Deleted = false,
173173
_IsRead = true,
174174
Subject = tmpSubject,
175-
Recipients = new PersonList<MagisterPerson>(this.Mata),
175+
Recipients = new PersonList(this.Mata),
176176
Ref = null,
177177
State = 0,
178178
SentDate = DateTime.UtcNow,
@@ -198,7 +198,7 @@ public MagisterMessage CreateReplyToAllMessage(string ContentAdd)
198198
Sender = this.Sender,
199199
_Folder = this._Folder,
200200
Attachments = new ReadOnlyCollection<Attachment>(new List<Attachment>()),
201-
CC = new PersonList<MagisterPerson>(this.Mata, tmpCC),
201+
CC = new PersonList(tmpCC, this.Mata),
202202
IsFlagged = this.IsFlagged,
203203
ID = this.ID,
204204
SenderGroupID = 4,
@@ -209,7 +209,7 @@ public MagisterMessage CreateReplyToAllMessage(string ContentAdd)
209209
Deleted = false,
210210
_IsRead = true,
211211
Subject = tmpSubject,
212-
Recipients = new PersonList<MagisterPerson>(this.Mata) { this.Sender },
212+
Recipients = new PersonList(this.Mata) { this.Sender },
213213
Ref = null,
214214
State = 0,
215215
SentDate = DateTime.UtcNow,
@@ -242,7 +242,7 @@ public MagisterMessage CreateReplyMessage(string ContentAdd)
242242
Deleted = false,
243243
_IsRead = true,
244244
Subject = tmpSubject,
245-
Recipients = new PersonList<MagisterPerson>(this.Mata) { this.Sender },
245+
Recipients = new PersonList(this.Mata) { this.Sender },
246246
Ref = null,
247247
State = 0,
248248
SentDate = DateTime.UtcNow,
@@ -396,10 +396,10 @@ internal partial class MagisterStyleMessage
396396

397397
public MagisterMessage ToMagisterMessage(int index)
398398
{
399-
var tmpReceivers = this.Ontvangers.ToList(true);
399+
var tmpReceivers = this.Ontvangers.ToList(true, true);
400400
tmpReceivers.Sort();
401401

402-
var tmpCopiedReceivers = this.KopieOntvangers.ToList(true);
402+
var tmpCopiedReceivers = this.KopieOntvangers.ToList(true, true);
403403
tmpCopiedReceivers.Sort();
404404

405405
return new MagisterMessage()

src/MataSharp/Mata.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void ComposeAndSendMessage(string Subject, string Body, IEnumerable<strin
9595
{
9696
Subject = Subject,
9797
Body = Body,
98-
Recipients = new PersonList<MagisterPerson>(this, Recipients)
98+
Recipients = new PersonList(Recipients, this)
9999
}.Send();
100100
}
101101

@@ -127,7 +127,7 @@ public bool ComposeAndTrySendMessage(string Subject, string Body, IEnumerable<st
127127
{
128128
Subject = Subject,
129129
Body = Body,
130-
Recipients = new PersonList<MagisterPerson>(this, Recipients)
130+
Recipients = new PersonList(Recipients, this)
131131
}.TrySend();
132132
}
133133

@@ -164,21 +164,21 @@ public List<MagisterMessageFolder> GetMessageFolders()
164164
/// </summary>
165165
/// <param name="SearchFilter">The search filter to use as string.</param>
166166
/// <returns>List containing MagisterPerson instances</returns>
167-
public List<MagisterPerson> GetPersons(string SearchFilter)
167+
public PersonList GetPersons(string SearchFilter)
168168
{
169-
if (string.IsNullOrWhiteSpace(SearchFilter) || SearchFilter.Length < 3) return new List<MagisterPerson>();
169+
if (string.IsNullOrWhiteSpace(SearchFilter) || SearchFilter.Length < 3) return new PersonList();
170170

171171
if (!_Session.checkedPersons.ContainsKey(SearchFilter))
172172
{
173173
string URL = "https://" + this.School.URL + "/api/personen/" + this.UserID + "/communicatie/contactpersonen?q=" + SearchFilter;
174174

175175
string personsRAW = _Session.HttpClient.DownloadString(URL);
176-
176+
177177
var personRaw = JArray.Parse(personsRAW).ToList().ConvertAll(p => p.ToObject<MagisterStylePerson>());
178178
_Session.checkedPersons.Add(SearchFilter, personRaw);
179-
return personRaw.ConvertAll(p => p.ToPerson(false));
179+
return new PersonList(this, personRaw,false, false);
180180
}
181-
else return _Session.checkedPersons.First(x => x.Key.ToUpper() == SearchFilter.ToUpper()).Value.ConvertAll(p => p.ToPerson(false));
181+
else return new PersonList(this, _Session.checkedPersons.First(x => x.Key.ToUpper() == SearchFilter.ToUpper()).Value,false, false);
182182
}
183183

184184
public List<Homework> GetHomework()

0 commit comments

Comments
 (0)