Hello Phillippe,
at the moment i stay on the line. Please can you make me a suggestion please?
I have changed now following steps:
RosterIndexViewModel.ccs - File:
namespace RosterManagementSystemWeb.Models.ViewModels
{
public class RosterIndexViewModel
{
public RosterIndexViewModel(int year, int month)
{
DaysofMonth = new List<DateTime>();
var d = new DateTime(year, month, 1);
while (d.Month == month)
{
DaysofMonth.Add(d);
d = d.AddDays(1);
}
}
public class MonthListView
{
// MonthList-Model for Dropdownlist
public int? SelectedMonth;
public SelectList MonthList
{
get
{
return new SelectList(AllMonths, "Index", "Name", SelectedMonth);
}
}
public IEnumerable<MonthInfo> AllMonths
{
get
{
CultureInfo info =
System.Threading.Thread.CurrentThread.CurrentCulture;
var today = DateTime.Today;
DateTime startDate = new DateTime(today.Year, today.Month, 1);
DateTime endDate = startDate.AddMonths(1).AddDays(-1);
int startYear = startDate.Year;
int startMonth = startDate.Month;
int index = 1;
foreach (var monthName in info.DateTimeFormat.MonthNames)
{
var testYear = index < startMonth ? startYear + 1 : startYear;
var testDate = new DateTime(testYear, index, 1);
if (testDate >= startDate && testDate < endDate)
{
yield return new MonthInfo { Index = index, Name = monthName };
}
++index;
}
}
}
public class MonthInfo
{
public int Index { get; set; }
public string Name { get; set; }
}
}
}
public class RosterGridRow
{
public Employee Employee { get; set; }
public IEnumerable<Roster> RosterEntries { get; set; }
public RosterGridRow()
{
RosterEntries = new List<Roster>();
}
}
}
RosterController.cs - File:
namespace RosterManagementSystemWeb.Controllers
{
public class RosterController : Controller
{
private RosterDb db = new RosterDb();
public ActionResult Index()
{
var data = new RosterIndexViewModel(2011, 8);
data.GridRows = (from e in db.EmployeeSet
select new RosterGridRow() { Employee = e }).ToList();
foreach (var gr in data.GridRows)
{
gr.RosterEntries = (from r in db.RosterSet
where r.EmployeeId == gr.Employee.Id
&& r.RosterDate >= startDate && r.RosterDate <= endDate
select r).ToList();
}
return View(data);
}
In the RosterController.cs on the line -> public RosterIndexViewModel(int year, int month), i'm not sure how can i get the right result.
I hope you can helo otherwise i must wait until to Thursday that help me my Trainer.
Thank you :)