//-----------------------------------------------------------------------
//
// Company copyright tag.
//
// stubbfel
// 03.05.2013
//----------------------------------------------------------------------
namespace CampusAppWPortalLib8.Model.Mensa
{
using System;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
///
/// Model for menus in one week
///
[XmlRoot("root")]
public class MenuWeekModel
{
#region Members
///
/// Time when the model was created
///
private readonly DateTime createTime;
#endregion
#region Constructor
///
/// Initializes a new instance of the class.
///
public MenuWeekModel()
{
this.createTime = DateTime.Now;
}
#endregion
#region Proberty
///
/// Gets or sets the menus for the week
///
[XmlArray("Mealplan")]
[XmlArrayItem("Menu")]
public ObservableCollection Menus { get; set; }
///
/// Gets the creation time of the model
///
public DateTime CreateTime
{
get
{
return this.createTime;
}
}
#endregion
#region Methods
///
/// Method calculate this day of the week, which its gets new menus
///
/// Date of NewMenuWeekDay
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;
}
///
/// Method determine holidays (Days with no meals) and add a pseudo meal
///
/// text of the pseudo meal
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();
}
menu.Meals.Add(holiday);
}
}
}
#endregion
}
}