add validation userprofile
This commit is contained in:
@@ -98,8 +98,8 @@
|
||||
</Compile>
|
||||
<Compile Include="Feed\Departments\DepartmentFavoriteFeed.cs" />
|
||||
<Compile Include="Const.cs" />
|
||||
<Compile Include="File\UserProfil\UserProfilFile.cs" />
|
||||
<Compile Include="Model\UserProfil\UserProfilModel.cs" />
|
||||
<Compile Include="File\Setting\UserProfilFile.cs" />
|
||||
<Compile Include="Model\Setting\UserProfilModel.cs" />
|
||||
<Compile Include="Pages\Setting\UserProfil.xaml.cs">
|
||||
<DependentUpon>UserProfil.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@@ -5,41 +5,38 @@
|
||||
// <author>stubbfel</author>
|
||||
// <sience>23.07.2013</sience>
|
||||
//----------------------------------------------------------------------
|
||||
namespace CampusAppWP8.File.UserProfil
|
||||
namespace CampusAppWP8.File.Setting
|
||||
{
|
||||
using CampusAppWP8.Model;
|
||||
using CampusAppWP8.Model.UserProfil;
|
||||
using CampusAppWP8.Resources;
|
||||
using CampusAppWP8.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CampusAppWP8.Model;
|
||||
using CampusAppWP8.Model.Setting;
|
||||
using CampusAppWP8.Resources;
|
||||
|
||||
/// <summary>
|
||||
/// Class for handle the user-profile-file
|
||||
/// </summary>
|
||||
public class UserProfilFile : XmlModel<UserProfilModel>
|
||||
{
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DepartmentFeed" /> class.
|
||||
/// Initializes a new instance of the <see cref="UserProfilFile" /> class.
|
||||
/// </summary>
|
||||
/// <param name="autoLoad">automatic loading of the data</param>
|
||||
public UserProfilFile(bool autoload = false) : base(ModelType.File, Constants.FileProfil_User)
|
||||
public UserProfilFile(bool autoLoad = false)
|
||||
: base(ModelType.File, Constants.FileProfil_User)
|
||||
{
|
||||
this.isFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDateOnLoad);
|
||||
this.isFileUpToDateOnSave += new IsFileUpToDate(this.CheckIsFileUpToDateOnSave);
|
||||
if (autoload)
|
||||
if (autoLoad)
|
||||
{
|
||||
this.LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Constructor
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Method implement CheckIsFileUpToDate()-Method <see cref="Pages"/>.
|
||||
/// </summary>
|
||||
278
CampusAppWP8/CampusAppWP8/Model/Setting/UserProfilModel.cs
Normal file
278
CampusAppWP8/CampusAppWP8/Model/Setting/UserProfilModel.cs
Normal file
@@ -0,0 +1,278 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <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_DefaultSemester);
|
||||
|
||||
/// <summary>
|
||||
/// constant for the default value of a role
|
||||
/// </summary>
|
||||
private static readonly int DefaultRole = int.Parse(Constants.Setting_DefaultRole);
|
||||
|
||||
/// <summary>
|
||||
/// constant for the default value of a degree
|
||||
/// </summary>
|
||||
private static readonly int DefaultDegree = int.Parse(Constants.Setting_DefaultDegree);
|
||||
|
||||
/// <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;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the role of the user
|
||||
/// </summary>
|
||||
private RoleType role = RoleType.DEFAULT;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the degree of the user
|
||||
/// </summary>
|
||||
private DegreeType degree = DegreeType.DEFAULT;
|
||||
|
||||
/// <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>
|
||||
/// Default value
|
||||
/// </summary>
|
||||
DEFAULT = UserProfilModel.DefaultRole,
|
||||
|
||||
/// <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>
|
||||
/// Default value
|
||||
/// </summary>
|
||||
DEFAULT = UserProfilModel.DefaultRole,
|
||||
|
||||
/// <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
|
||||
}
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="UserProfilModel.cs" company="BTU/IIT">
|
||||
// Company copyright tag.
|
||||
// </copyright>
|
||||
// <author>stubbfel</author>
|
||||
// <sience>23.07.2013</sience>
|
||||
//----------------------------------------------------------------------
|
||||
namespace CampusAppWP8.Model.UserProfil
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// Model for the profil of an user
|
||||
/// </summary>
|
||||
[XmlRoot("root")]
|
||||
public class UserProfilModel
|
||||
{
|
||||
|
||||
private bool changed = false;
|
||||
/// <summary>
|
||||
/// Gets or Sets the course of the user
|
||||
/// </summary>
|
||||
private string course;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the role of the user
|
||||
/// </summary>
|
||||
private int role;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the degree of the user
|
||||
/// </summary>
|
||||
private string degree;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the semester of the user
|
||||
/// </summary>
|
||||
private string semester;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the course of the user
|
||||
/// </summary>
|
||||
[XmlElement("Course")]
|
||||
public string Course
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.course;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != this.course)
|
||||
{
|
||||
this.course = value;
|
||||
this.changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the role of the user
|
||||
/// </summary>
|
||||
[XmlElement("Role")]
|
||||
public int 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 string 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 string Semester
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.semester;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != this.semester)
|
||||
{
|
||||
this.semester = value;
|
||||
this.changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the role of the user.
|
||||
/// </summary>
|
||||
public enum RoleType
|
||||
{
|
||||
/// <summary>
|
||||
/// Invalid/unset state.
|
||||
/// </summary>
|
||||
INVALID = 0,
|
||||
|
||||
/// <summary>
|
||||
/// for students (01).
|
||||
/// </summary>
|
||||
Student = 1,
|
||||
|
||||
/// <summary>
|
||||
/// for staffs (10).
|
||||
/// </summary>
|
||||
Staff = 2,
|
||||
}
|
||||
|
||||
public bool HasChanged(bool reset = true)
|
||||
{
|
||||
bool result = this.changed;
|
||||
|
||||
if (reset)
|
||||
{
|
||||
changed = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,6 +429,42 @@ namespace CampusAppWP8.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die 767 ähnelt.
|
||||
/// </summary>
|
||||
public static string Setting_DefaultCourseNumber {
|
||||
get {
|
||||
return ResourceManager.GetString("Setting_DefaultCourseNumber", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die 82 ähnelt.
|
||||
/// </summary>
|
||||
public static string Setting_DefaultDegree {
|
||||
get {
|
||||
return ResourceManager.GetString("Setting_DefaultDegree", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die 1 ähnelt.
|
||||
/// </summary>
|
||||
public static string Setting_DefaultRole {
|
||||
get {
|
||||
return ResourceManager.GetString("Setting_DefaultRole", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die 20131 ähnelt.
|
||||
/// </summary>
|
||||
public static string Setting_DefaultSemester {
|
||||
get {
|
||||
return ResourceManager.GetString("Setting_DefaultSemester", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die ToggleContent ähnelt.
|
||||
/// </summary>
|
||||
@@ -537,6 +573,33 @@ namespace CampusAppWP8.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die 20121 ähnelt.
|
||||
/// </summary>
|
||||
public static string Valid_FirstSemseter {
|
||||
get {
|
||||
return ResourceManager.GetString("Valid_FirstSemseter", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die 20502 ähnelt.
|
||||
/// </summary>
|
||||
public static string Valid_LastSemseter {
|
||||
get {
|
||||
return ResourceManager.GetString("Valid_LastSemseter", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die 999 ähnelt.
|
||||
/// </summary>
|
||||
public static string Valid_MaxCourseNumber {
|
||||
get {
|
||||
return ResourceManager.GetString("Valid_MaxCourseNumber", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die root ähnelt.
|
||||
/// </summary>
|
||||
|
||||
@@ -279,4 +279,25 @@
|
||||
<data name="PathSetting_User" xml:space="preserve">
|
||||
<value>/Pages/Setting/UserProfil.xaml</value>
|
||||
</data>
|
||||
<data name="Setting_DefaultCourseNumber" xml:space="preserve">
|
||||
<value>767</value>
|
||||
</data>
|
||||
<data name="Setting_DefaultDegree" xml:space="preserve">
|
||||
<value>82</value>
|
||||
</data>
|
||||
<data name="Setting_DefaultRole" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name="Setting_DefaultSemester" xml:space="preserve">
|
||||
<value>20131</value>
|
||||
</data>
|
||||
<data name="Valid_FirstSemseter" xml:space="preserve">
|
||||
<value>20121</value>
|
||||
</data>
|
||||
<data name="Valid_LastSemseter" xml:space="preserve">
|
||||
<value>20502</value>
|
||||
</data>
|
||||
<data name="Valid_MaxCourseNumber" xml:space="preserve">
|
||||
<value>999</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -1,20 +1,41 @@
|
||||
using CampusAppWP8.File.UserProfil;
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="Settings.cs" company="BTU/IIT">
|
||||
// Company copyright tag.
|
||||
// </copyright>
|
||||
// <author>stubbfel</author>
|
||||
// <sience>23.07.2013</sience>
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
namespace CampusAppWP8
|
||||
{
|
||||
using CampusAppWP8.File.Setting;
|
||||
|
||||
/// <summary>
|
||||
/// Class handle all setting (files)
|
||||
/// </summary>
|
||||
public class Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// reference of the user-profile-file
|
||||
/// </summary>
|
||||
private static UserProfilFile userProfil = new UserProfilFile(true);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user-profile-file
|
||||
/// </summary>
|
||||
public static UserProfilFile UserProfil
|
||||
{
|
||||
get
|
||||
{
|
||||
return UserProfil;
|
||||
return Settings.userProfil;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
UserProfil = value;
|
||||
if (value != Settings.userProfil)
|
||||
{
|
||||
Settings.userProfil = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user