105 lines
2.7 KiB
C#
105 lines
2.7 KiB
C#
//-----------------------------------------------------------------------
|
|
// <copyright file="MenuWeekModel.cs" company="BTU/IIT">
|
|
// Company copyright tag.
|
|
// </copyright>
|
|
// <author>stubbfel</author>
|
|
// <sience>03.05.2013</sience>
|
|
//----------------------------------------------------------------------
|
|
namespace CampusAppWP8ScheduledTaskAgent.Model.Mensa
|
|
{
|
|
using CampusAppWP8ScheduledTaskAgent.Utility;
|
|
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Xml.Serialization;
|
|
|
|
/// <summary>
|
|
/// Model for menus in one week
|
|
/// </summary>
|
|
[XmlRoot("root")]
|
|
public class MenuWeekModel
|
|
{
|
|
#region Members
|
|
/// <summary>
|
|
/// Time when the model was created
|
|
/// </summary>
|
|
private readonly DateTime createTime;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="MenuWeekModel" /> class.
|
|
/// </summary>
|
|
public MenuWeekModel()
|
|
{
|
|
this.createTime = DateTime.Now;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Proberty
|
|
|
|
/// <summary>
|
|
/// Gets or sets the menus for the week
|
|
/// </summary>
|
|
[XmlArray("Mealplan")]
|
|
[XmlArrayItem("Menu")]
|
|
public ObservableCollection<MenuModel> Menus { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets the creation time of the model
|
|
/// </summary>
|
|
public DateTime CreateTime
|
|
{
|
|
get
|
|
{
|
|
return this.createTime;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
public string MealToString(string date)
|
|
{
|
|
string mealString = string.Empty;
|
|
|
|
foreach (MenuModel menu in this.Menus)
|
|
{
|
|
if (menu.Date.Equals(date))
|
|
{
|
|
foreach (MealModel meal in menu.Meals)
|
|
{
|
|
int lenght = meal.MealDesc.Length;
|
|
if (lenght > 30) {
|
|
lenght = 30;
|
|
}
|
|
mealString += meal.MealName + ": " + meal.MealDesc.Substring(0, lenght) +"...";
|
|
mealString = StringManager.AddNewLine(mealString);
|
|
}
|
|
return mealString;
|
|
}
|
|
}
|
|
|
|
return mealString;
|
|
}
|
|
|
|
public int GetMealCount(string date)
|
|
{
|
|
foreach (MenuModel menu in this.Menus)
|
|
{
|
|
if (menu.Date.Equals(date))
|
|
{
|
|
return menu.Meals.Count;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|