Files
win8phoneApp/CampusAppWP8/CampusAppWPortalLib8/Model/Person/PersonListModel.cs
2013-10-02 13:27:45 +02:00

105 lines
3.2 KiB
C#

//-----------------------------------------------------------------------------
// <copyright file="PersonListModel.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>05.09.2013</sience>
//-----------------------------------------------------------------------------
namespace CampusAppWPortalLib8.Model.Person
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
/// <summary>Person list model.</summary>
/// <remarks>Stubbfel, 05.09.2013.</remarks>
/// <typeparam name="T">personModel template</typeparam>
[XmlRoot("Uebersicht")]
public class PersonListModel<T>
{
#region Property
/// <summary>Gets or sets the persons.</summary>
/// <value>The persons.</value>
[XmlElement("person")]
public ObservableCollection<T> Persons { get; set; }
#endregion
#region Method
/// <summary>Sets person identifier to function.</summary>
/// <remarks>Stubbfel, 05.09.2013.</remarks>
public void SetPersonIdToFunction()
{
foreach (T item in this.Persons)
{
IPersonModel<IPersonFunctionModel> person = item as IPersonModel<IPersonFunctionModel>;
if (person != null)
{
person.SetPersonIdToFunction();
}
}
}
/// <summary>Gets a person.</summary>
/// <remarks>Stubbfel, 05.09.2013.</remarks>
/// <param name="id">The identifier.</param>
/// <returns>The person.</returns>
public IPersonModel<IPersonFunctionModel> GetPerson(string id)
{
foreach (T item in this.Persons)
{
IPersonModel<IPersonFunctionModel> tmpPerson = item as IPersonModel<IPersonFunctionModel>;
if (tmpPerson == null)
{
continue;
}
if (tmpPerson.ID.Equals(id))
{
return tmpPerson;
}
}
return default(IPersonModel<IPersonFunctionModel>);
}
/// <summary>Removes the non function and set identifiers person.</summary>
/// <remarks>Stubbfel, 05.09.2013.</remarks>
public void RemoveNonFunctionAndSetIdsPerson()
{
this.RemoveNonFunctionPerson();
this.SetPersonIdToFunction();
}
/// <summary>Removes the non function person.</summary>
/// <remarks>Stubbfel, 05.09.2013.</remarks>
public void RemoveNonFunctionPerson()
{
List<T> removeList = new List<T>();
foreach (T item in this.Persons)
{
IPersonModel<IPersonFunctionModel> tmpPerson = item as IPersonModel<IPersonFunctionModel>;
if (tmpPerson == null)
{
continue;
}
if (tmpPerson.Functions.Count < 1)
{
removeList.Add(item);
}
}
foreach (T removePerson in removeList)
{
this.Persons.Remove(removePerson);
}
}
#endregion
}
}