Saving worked hours in Database
HI everybody,
I have this:
[code]
public class Hour:Modelbase
{
public string Name { get; set; }
public string Url { get; set; }
public int HourID { get; set; }
public virtual Week Week { get; set; }
public int? WeekID { get; set; }
//[DisplayFormat(ApplyFormatInEditMode=true, DataFormatString="{0:c}")]
public decimal Amount { get; set; }
[ReadOnly(true)]
public decimal HourTotal { get; set; }
public int WeekNumber { get; set; }
public int yearNumber { get; set; }
//Properties days:
public int Days { get; set; }
public DayOfWeek DayWeek { get; set; }
public DateTime DateDay { get; set; }
[DataType(DataType.Date)]
public DateTime Monday { get; set; }
[DataType(DataType.Date)]//
public DateTime Tuesday { get; set; }
[DataType(DataType.Date)]
[ReadOnly(true)]
public DateTime Wendsday { get; set; }
[DataType(DataType.Date)]
public DateTime Thursday { get; set; }
[DataType(DataType.Date)]
public DateTime Fryday { get; set; }
[DataType(DataType.Date)]
public DateTime Saterday { get; set; }
[DataType(DataType.Date)]
public DateTime Sunday { get; set; }
//End properties days
//Properties hours:
public Decimal MondayHours { get; set; }
public Decimal TuesdayHours { get; set; }
public Decimal WendsdayHours { get; set; }
public Decimal ThursdayHours { get; set; }
public Decimal FrydayHours { get; set; }
public Decimal SaterdayHours { get; set; }
public Decimal SundayHOurs { get; set; }
public decimal GetTotalHours()
{
return MondayHours +
TuesdayHours +
WendsdayHours +
ThursdayHours +
FrydayHours +
SaterdayHours +
SundayHOurs;
}
//public IEnumerable<SelectListItem> Hour { get; set; }
public Hour()
{
//Year = DateTime.Now.AddYears(0);
//DayWeek = DateTime.Now.DayOfWeek;
this.yearNumber = DateTime.Now.Year;
Days = DateTime.Now.DayOfWeek - DayOfWeek.Monday;
Monday = DateTime.Now.AddDays(-Days);
Tuesday = DateTime.Parse(Monday.AddDays(1).ToShortDateString());//.ToShortDateString());
Wendsday = DateTime.Parse(Monday.AddDays(2).ToShortDateString());
Thursday = DateTime.Parse(Monday.AddDays(3).ToShortDateString());
Fryday = DateTime.Parse(Monday.AddDays(4).ToShortDateString());
Saterday = DateTime.Parse(Monday.AddDays(5).ToShortDateString());
Sunday = DateTime.Parse(Monday.AddDays(6).ToShortDateString());
//this.WeekNumber = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar.GetWeekOfYear(DateTime.Now, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
}
}
[/code]
and a class Week:
[code]
public class Week
{
public int WeekID { get; set; }
public string Name { get; set; }
[DataType(DataType.Date)]
public int? WeekNumber { get; set; }
public virtual IEnumerable<Hour> Hour { get; set; }
TimeSheetContext _context = new TimeSheetContext();
public int SelectID { get; set; }
public DateTime WeekNumberss { get; set; }
//[DataType(DataType.Date)]
public int YearNumber { get; set; }
public Week(/*int YearNumber*/)
{
YearNumber = DateTime.Now.Year;// .AddYears(0);
}
}
[/code]
But how now to save the hours associated with for example the date for Monday, I have now 7 textboxes: Monday, tuesday, ..etc en under the date u can put the hours u have worked. But how to map the hours associated with the date of that day. For example U have monday(2-01-2012)and u fill in the texbox working hours: 8 hour. How do u know now that for monday(2-01-2012) there are 8 hours of working.
Do I miss an extra table?
I also included the hole project.
THX for helping.