public ActionResult Reports(string sdate, string[] IsWeekly) { var model = new ReservationPrintable(); model.IsWeekly = true; if (IsWeekly != null) { model.IsWeekly = Boolean.Parse(IsWeekly[0]); } var date = sdate == null ? DateTime.Today : DateTime.ParseExact(sdate, "dd.MM.yyyy", CultureInfo.InvariantCulture); if (model.IsWeekly) { var diff = date.DayOfWeek - CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek; if (diff < 0) { diff += 7; } date = date.AddDays(-diff); } model.Date = date; using (IUnitOfWork uow = new UnitOfWork(new DbContextWrap())) { var days = model.IsWeekly ? 5 : 1; for (var i = 0; i < days; i++) { var view = new ReservationView { Tables = _repository.GetAll <TableModel>(uow).ToList(), Times = _repository.GetAll <TimeModel>(uow).ToList(), Date = date.AddDays(i) }; view.Day = _reservationManager.GetReservationsForDate(uow, view.Date, view.Tables, User.Identity.GetUserId()); var users = _reservationManager.GetUsersForDate(uow, view.Date); model.AddUsers(HttpContext.GetOwinContext() .GetUserManager <ApplicationUserManager>() .Users .Where(u => users.Contains(u.Id)) .Select(u => new MyUser { Id = u.Id, UserName = u.UserName, Name = u.Name }) .ToList() .ToDictionary(u => u.Id)); model.AddDay(view); } } return(View("Reports", model)); }