Files
win8phoneApp/CampusAppWP8/CampusAppWPortalLib8/Model/Mensa/MenuWeekModel.cs
2013-10-15 13:10:29 +02:00

100 lines
3.1 KiB
C#

//-----------------------------------------------------------------------
// <copyright file="MenuWeekModel.cs" company="BTU/IIT">
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
// </copyright>
// <author>Stubbfel</author>
// <date>15.10.2013</date>
// <summary>Implements the menu week model class</summary>
//-----------------------------------------------------------------------
namespace CampusAppWPortalLib8.Model.Mensa
{
using System;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
/// <summary> Model for menus in one week. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
[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>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
public MenuWeekModel()
{
this.createTime = DateTime.Now;
}
#endregion
#region Proberty
/// <summary> Gets or sets the menus for the week. </summary>
/// <value> The menus. </value>
[XmlArray("Mealplan")]
[XmlArrayItem("Menu")]
public ObservableCollection<MenuModel> Menus { get; set; }
/// <summary> Gets the creation time of the model. </summary>
/// <value> The create time. </value>
public DateTime CreateTime
{
get
{
return this.createTime;
}
}
#endregion
#region Methods
/// <summary> Method calculate this day of the week, which its gets new menus. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
/// <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>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
/// <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
}
}