// // RateControl.cs // // Author: // Paul Schneider // // Copyright (c) 2015 GNU GPL // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . using System; using System.Web.Mvc; using Yavsc.Model; namespace Yavsc { /// /// Rate control. /// public class RateControl : ViewUserControl where TModel : IRating { /// /// Initializes a new instance of the Yavsc.Blogs.RateControl class. /// public RateControl () { } /// /// Gets or sets the rate, that is, an integer between 0 and 100 /// /// The rate. public int Rate { get { return (int) ViewState["rate"]; } set { ViewState["rate"] = value; int rate = value; int rounded = (rate / 10); HasHalf = rounded % 2 == 1; NbFilled = (int)rounded / 2; NbEmpty = (5 - NbFilled) - ((HasHalf)?1:0) ; } } /// /// Gets the nb filed. /// /// The nb filed. public int NbFilled { set { ViewState["nbfilled"] = value; } get { return (int) ViewState["nbfilled"]; } } /// /// Gets the nb empty. /// /// The nb empty. public int NbEmpty { set { ViewState["nbempty"] = value; } get { return (int) ViewState["nbempty"]; } } /// /// Gets a value indicating whether this instance has half. /// /// true if this instance has half; otherwise, false. public bool HasHalf { set { ViewState["hashalf"] = value; } get { return (bool) ViewState["hashalf"]; } } protected override void OnInit (EventArgs e) { base.OnInit (e); Rate = this.Model.Rate; } } }