Files
win8phoneApp/CampusAppWP8/CampusAppWPortalLib8/Model/Mensa/MenuWeekModel.cs
2013-10-08 15:18:01 +02:00

106 lines
2.8 KiB
C#

//-----------------------------------------------------------------------
// <copyright file="MenuWeekModel.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>03.05.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWPortalLib8.Model.Mensa
{
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
/// <summary>
/// Method calculate this day of the week, which its gets new menus
/// </summary>
/// <returns>Date of NewMenuWeekDay</returns>
public static DateTime CalcFirstWeekDay()
{
DateTime now = DateTime.Now;
while (now.DayOfWeek != DayOfWeek.Monday)
{
now = now.Subtract(new TimeSpan(1, 0, 0, 0));
}
DateTime monday = new DateTime(now.Year, now.Month, now.Day);
return monday;
}
/// <summary>
/// Method determine holidays (Days with no meals) and add a pseudo meal
/// </summary>
/// <param name="text">text of the pseudo meal</param>
public void SetHolidayCaption(string text)
{
MealModel holiday = new MealModel();
holiday.MealDesc = text;
holiday.MealId= -1;
foreach (MenuModel menu in this.Menus)
{
if (menu.Meals == null || menu.Meals.Count < 1)
{
if (menu.Meals == null)
{
menu.Meals = new ObservableCollection<MealModel>();
}
menu.Meals.Add(holiday);
}
}
}
#endregion
}
}