refactor person models

This commit is contained in:
stubbfel
2013-10-21 13:35:11 +02:00
parent 02fc7e4ba5
commit b4469549be
10 changed files with 75 additions and 132 deletions

View File

@@ -9,59 +9,12 @@
namespace CampusAppWP8.Model.Person
{
using System.Xml.Serialization;
using CampusAppWPortalLib8.Model.Person;
using System.Collections.Generic;
/// <summary> Person list model. </summary>
/// <remarks> Stubbfel, 05.09.2013. </remarks>
/// <seealso cref="T:CampusAppWPortalLib8.Model.Person.PersonListModel{CampusAppWP8.Model.Person.PersonWp8Model}"/>
[XmlRoot("Uebersicht")]
public class PersonListWp8Model : CampusAppWPortalLib8.Model.Person.PersonListModel<PersonWp8Model>
public class PersonListWp8Model : CampusAppWPortalLib8.Model.Person.PersonListModel<PersonWp8Model, PersonFunctionWp8Model>
{
/// <summary> Gets a person. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
/// <param name="id"> The identifier. </param>
/// <returns> The person. </returns>
public override PersonWp8Model GetPerson(string id)
{
foreach (PersonWp8Model tmpPerson in this.Persons)
{
if (tmpPerson.ID.Equals(id))
{
return tmpPerson;
}
}
return null;
}
/// <summary> Removes the non function person. </summary>
/// <remarks> Stubbfel, 05.09.2013. </remarks>
public override void RemoveNonFunctionPerson()
{
List<PersonWp8Model> removeList = new List<PersonWp8Model>();
foreach (PersonWp8Model tmpPerson in this.Persons)
{
if (tmpPerson.Functions.Count < 1)
{
removeList.Add(tmpPerson);
}
}
foreach (PersonWp8Model removePerson in removeList)
{
this.Persons.Remove(removePerson);
}
}
/// <summary> Sets person identifier to function. </summary>
/// <remarks> Stubbfel, 05.09.2013. </remarks>
public override void SetPersonIdToFunction()
{
foreach (PersonWp8Model person in this.Persons)
{
person.SetPersonIdToFunction();
}
}
}
}

View File

@@ -11,8 +11,8 @@ namespace CampusAppWP8.Model.Person
using System.Xml.Serialization;
using CampusAppWP8.Utility;
/// <summary> Person model. </summary>
/// <remarks> Stubbfel, 05.09.2013. </remarks>
/// <summary> A data Model for the person . </summary>
/// <remarks> Stubbfel, 21.10.2013. </remarks>
/// <seealso cref="T:CampusAppWPortalLib8.Model.Person.PersonModel{CampusAppWP8.Model.Person.PersonFunctionWp8Model}"/>
public class PersonWp8Model : CampusAppWPortalLib8.Model.Person.PersonModel<PersonFunctionWp8Model>
{

View File

@@ -132,15 +132,16 @@ namespace CampusAppWP8.Pages.Person
saveContactTask.FirstName = person.FirstName;
saveContactTask.LastName = person.SurName;
saveContactTask.Title = person.Akadgrad;
saveContactTask.JobTitle = person.Functions[functionIndex].Function;
saveContactTask.Company = Constants.Addr_CBMainCompanyName + " - " + person.Functions[functionIndex].Appointment;
PersonFunctionWp8Model personFunction = person.Functions[functionIndex];
saveContactTask.JobTitle = personFunction.Function;
saveContactTask.Company = Constants.Addr_CBMainCompanyName + " - " + personFunction.Appointment;
saveContactTask.WorkAddressCountry = Constants.Addr_CBMainCountry;
saveContactTask.WorkAddressCity = Constants.Addr_CBMainCity;
saveContactTask.WorkAddressState = Constants.Addr_CBMainState;
saveContactTask.WorkAddressZipCode = Constants.Addr_CBMainZipCode;
saveContactTask.WorkAddressStreet = person.Functions[functionIndex].Building;
saveContactTask.WorkPhone = person.Functions[functionIndex].Tel1;
saveContactTask.WorkEmail = person.Functions[functionIndex].Mail;
saveContactTask.WorkAddressStreet = personFunction.Building;
saveContactTask.WorkPhone = personFunction.Tel;
saveContactTask.WorkEmail = personFunction.Mail;
saveContactTask.Show();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 58 KiB

View File

@@ -53,8 +53,6 @@
<Compile Include="Model\ModelTypes.cs" />
<Compile Include="Model\Openinghours\OpeninghoursInstitutionModel.cs" />
<Compile Include="Model\Openinghours\OpeninghoursModel.cs" />
<Compile Include="Model\Person\IPersonFunctionModel.cs" />
<Compile Include="Model\Person\IPersonModel.cs" />
<Compile Include="Model\Person\PersonFunctionModel.cs" />
<Compile Include="Model\Person\PersonListModel.cs" />
<Compile Include="Model\Person\PersonModel.cs" />

View File

@@ -1,23 +0,0 @@
//-----------------------------------------------------------------------
// <copyright file="IPersonFunctionModel.cs" company="BTU/IIT">
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
// </copyright>
// <author>Stubbfel</author>
// <date>15.10.2013</date>
// <summary>Declares the IPersonFunctionModel interface</summary>
//-----------------------------------------------------------------------
namespace CampusAppWPortalLib8.Model.Person
{
/// <summary> Interface for PersonFunctionModel classes. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
public interface IPersonFunctionModel
{
/// <summary> Gets or sets the identifier of the person. </summary>
/// <value> The identifier of the person. </value>
string PersonID { get; set; }
/// <summary> Gets or sets zero-based index of the function. </summary>
/// <value> The function index. </value>
int FunctionIndex { get; set; }
}
}

View File

@@ -1,30 +0,0 @@
//-----------------------------------------------------------------------
// <copyright file="IPersonModel.cs" company="BTU/IIT">
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
// </copyright>
// <author>Stubbfel</author>
// <date>15.10.2013</date>
// <summary>Declares the IPersonModel interface</summary>
//-----------------------------------------------------------------------
namespace CampusAppWPortalLib8.Model.Person
{
using System.Collections.ObjectModel;
/// <summary> Interface for PersonModel classes. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
/// <typeparam name="T"> PersonFunctionModel template. </typeparam>
public interface IPersonModel<T> where T : IPersonFunctionModel
{
/// <summary> Gets or sets the functions of a person. </summary>
/// <value> The functions. </value>
ObservableCollection<T> Functions { get; set; }
/// <summary> Gets or sets the identifier. </summary>
/// <value> The identifier. </value>
string ID { get; set; }
/// <summary> Sets person identifier to function. </summary>
/// <remarks> Stubbfel, 05.09.2013. </remarks>
void SetPersonIdToFunction();
}
}

View File

@@ -14,7 +14,7 @@ namespace CampusAppWPortalLib8.Model.Person
/// <summary> Person function model. </summary>
/// <remarks> Stubbfel, 05.09.2013. </remarks>
/// <seealso cref="T:CampusAppWPortalLib8.Model.Person.IPersonFunctionModel"/>
public class PersonFunctionModel : IPersonFunctionModel
public class PersonFunctionModel
{
#region Member
@@ -62,6 +62,19 @@ namespace CampusAppWPortalLib8.Model.Person
}
}
public string Tel
{
get
{
return this.Tel1;
}
set
{
this.Tel1 = value;
}
}
/// <summary> Gets or sets the tel 2. </summary>
/// <value> The tel 2. </value>
[XmlAttribute("telefon2")]

View File

@@ -12,11 +12,14 @@ namespace CampusAppWPortalLib8.Model.Person
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>
/// <summary> A data Model for the person list. </summary>
/// <remarks> Stubbfel, 21.10.2013. </remarks>
/// <typeparam name="T"> Generic type parameter (PersonModel). </typeparam>
/// <typeparam name="V"> Generic type parameter (PersonFunctionModel). </typeparam>
[XmlRoot("Uebersicht")]
public abstract class PersonListModel<T>
public abstract class PersonListModel<T, V>
where V : PersonFunctionModel
where T : PersonModel<V>
{
#region Property
@@ -29,15 +32,22 @@ namespace CampusAppWPortalLib8.Model.Person
#region Method
/// <summary> Sets person identifier to function. </summary>
/// <remarks> Stubbfel, 05.09.2013. </remarks>
public abstract void SetPersonIdToFunction();
/// <summary> Gets a person. </summary>
/// <remarks> Stubbfel, 05.09.2013. </remarks>
/// <param name="id"> The identifier. </param>
/// <returns> The person. </returns>
public abstract T GetPerson(string id);
public T GetPerson(string id)
{
foreach (T tmpPerson in this.Persons)
{
if (tmpPerson.ID.Equals(id))
{
return tmpPerson;
}
}
return default(T);
}
/// <summary> Removes the non function and set identifiers person. </summary>
/// <remarks> Stubbfel, 05.09.2013. </remarks>
@@ -49,8 +59,33 @@ namespace CampusAppWPortalLib8.Model.Person
/// <summary> Removes the non function person. </summary>
/// <remarks> Stubbfel, 05.09.2013. </remarks>
public abstract void RemoveNonFunctionPerson();
public void RemoveNonFunctionPerson()
{
List<T> removeList = new List<T>();
foreach (T tmpPerson in this.Persons)
{
if (tmpPerson.Functions.Count < 1)
{
removeList.Add(tmpPerson);
}
}
foreach (T removePerson in removeList)
{
this.Persons.Remove(removePerson);
}
}
/// <summary> Sets person identifier to function. </summary>
/// <remarks> Stubbfel, 05.09.2013. </remarks>
public void SetPersonIdToFunction()
{
foreach (T person in this.Persons)
{
person.SetPersonIdToFunction();
}
}
#endregion
}
}

View File

@@ -12,9 +12,9 @@ namespace CampusAppWPortalLib8.Model.Person
using System.Xml.Serialization;
/// <summary> A data Model for the person. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
/// <seealso cref="T:CampusAppWPortalLib8.Model.Person.IPersonModel{T}"/>
public class PersonModel<T> : IPersonModel<T> where T : IPersonFunctionModel
/// <remarks> Stubbfel, 21.10.2013. </remarks>
/// <typeparam name="T"> Generic type parameter (PersonFunctionModel). </typeparam>
public class PersonModel<T> where T : PersonFunctionModel
{
#region Member
@@ -158,14 +158,10 @@ namespace CampusAppWPortalLib8.Model.Person
}
int index = 0;
foreach (T item in this.functions)
foreach (PersonFunctionModel function in this.functions)
{
IPersonFunctionModel function = item as IPersonFunctionModel;
if (function != null)
{
function.PersonID = this.ID;
function.FunctionIndex = index++;
}
function.PersonID = this.ID;
function.FunctionIndex = index++;
}
}