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