Files
win8phoneApp/CampusAppWP8/CampusAppWP8/Model/Setting/UserProfilModel.cs
2013-08-05 11:18:32 +02:00

259 lines
6.7 KiB
C#

//-----------------------------------------------------------------------
// <copyright file="UserProfilModel.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>23.07.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWP8.Model.Setting
{
using System.Xml.Serialization;
using CampusAppWP8.Resources;
/// <summary>
/// Model for the profile of an user
/// </summary>
[XmlRoot("root")]
public class UserProfilModel
{
#region Members
/// <summary>
/// constant for the first validate semester
/// </summary>
private static readonly int FirstSemester = int.Parse(Constants.Valid_FirstSemseter);
/// <summary>
/// constant for the last validate semester
/// </summary>
private static readonly int LastSemester = int.Parse(Constants.Valid_LastSemseter);
/// <summary>
/// constant for the max. number of a validate course
/// </summary>
private static readonly int MaxCourseNumber = int.Parse(Constants.Valid_MaxCourseNumber);
/// <summary>
/// constant for the default value of a semester
/// </summary>
private static readonly int DefaultSemester = int.Parse(Constants.Setting_DefaultSemester);
/// <summary>
/// constant for the default value of a courseNumber
/// </summary>
private static readonly int DefaultCourseNumber = int.Parse(Constants.Setting_DefaultCourseNumber);
/// <summary>
/// Flag which indicates that any properties has been changed
/// </summary>
private bool changed = false;
/// <summary>
/// Gets or Sets the course of the user
/// </summary>
private int course = UserProfilModel.DefaultCourseNumber;
/// <summary>
/// Gets or Sets the role of the user
/// </summary>
private RoleType role = RoleType.STUDENT;
/// <summary>
/// Gets or Sets the degree of the user
/// </summary>
private DegreeType degree = DegreeType.BACHELOR;
/// <summary>
/// Gets or Sets the semester of the user
/// </summary>
private int semester = UserProfilModel.DefaultSemester;
#endregion
#region Enums
/// <summary>
/// Specifies the degrees.
/// </summary>
public enum DegreeType
{
/// <summary>
/// bachelor degree
/// </summary>
BACHELOR = 82,
/// <summary>
/// master degree
/// </summary>
MASTER = 88,
/// <summary>
/// diploma degree
/// </summary>
DIPLOM = 11
}
/// <summary>
/// Specifies the role of the user.
/// </summary>
public enum RoleType
{
/// <summary>
/// for students (01).
/// </summary>
STUDENT = 1,
/// <summary>
/// for staffs (10).
/// </summary>
STAFF = 2,
}
#endregion
#region Proberties
/// <summary>
/// Gets or sets the course of the user
/// </summary>
[XmlElement("Course")]
public int Course
{
get
{
return this.course;
}
set
{
if (value != this.course && this.ValditateCourse(value))
{
this.course = value;
this.changed = true;
}
}
}
/// <summary>
/// Gets or sets the role of the user
/// </summary>
[XmlElement("Role")]
public RoleType Role
{
get
{
return this.role;
}
set
{
if (value != this.role)
{
this.role = value;
this.changed = true;
}
}
}
/// <summary>
/// Gets or sets the degree of the user
/// </summary>
[XmlElement("Degere")]
public DegreeType Degree
{
get
{
return this.degree;
}
set
{
if (value != this.degree)
{
this.degree = value;
this.changed = true;
}
}
}
/// <summary>
/// Gets or sets the semester of the user
/// </summary>
[XmlElement("Semseter")]
public int Semester
{
get
{
return this.semester;
}
set
{
if (value != this.semester && this.ValditateSemester(value))
{
this.semester = value;
this.changed = true;
}
}
}
#endregion
#region Methods
#region public
/// <summary>
/// Method return the changed flag
/// </summary>
/// <param name="reset"> if is true, set changed flag to false, otherwise do nothing (bypass)</param>
/// <returns>return true, if any properties has changed, otherwise false</returns>
public bool HasChanged(bool reset = true)
{
bool result = this.changed;
if (reset)
{
this.changed = false;
}
return result;
}
#endregion
#region private
/// <summary>
/// Methods check if a value could be a valid semester
/// </summary>
/// <param name="possibleSemester">value which has to be checked</param>
/// <returns>true if it is an valid semester, otherwise false</returns>
private bool ValditateSemester(int possibleSemester)
{
if (possibleSemester < UserProfilModel.FirstSemester || possibleSemester > UserProfilModel.LastSemester)
{
return false;
}
return true;
}
/// <summary>
/// Methods check if a value could be a valid course
/// </summary>
/// <param name="possibleCourse">value which has to be checked</param>
/// <returns>true if it is an valid course, otherwise false</returns>
private bool ValditateCourse(int possibleCourse)
{
if (possibleCourse > UserProfilModel.MaxCourseNumber)
{
return false;
}
return true;
}
#endregion
#endregion
}
}