public IActionResult DailyCounter(DateViewModel model) { using var db = new GuestCounterContext(_dbContextOptions); int count = 0; foreach (var day in db.Visitors) { if (day.RaportDate.Date == model.Date.Date) { count += day.GuestsIn; } } DailyCounterViewModel counter = new DailyCounterViewModel { Date = model.Date, Visitors = count }; return(View("DailyStats", counter)); }
public IActionResult Statistics(StatParamsViewModel model) { using var db = new GuestCounterContext(_dbContextOptions); var statList = new List <StatisticsViewModel>(); foreach (var raport in db.Visitors) { if (raport.RaportDate.Date >= model.BeginDate && raport.RaportDate.Date <= model.EndDate) { StatisticsViewModel stat = new StatisticsViewModel { RaportDate = raport.RaportDate, GuestsIn = raport.GuestsIn, GuestsOut = raport.GuestsOut }; statList.Add(stat); } } return(RedirectToAction("DisplayStatistics", statList)); }
public IActionResult Index() { using var db = new GuestCounterContext(_dbContextOptions); GuestsInfoViewModel model = new GuestsInfoViewModel { CurrentDate = DateTime.Now, GuestsInside = 0, GuestsIn = 0, GuestsOut = 0 }; foreach (var raport in db.Visitors) { if (raport.RaportDate.Date == model.CurrentDate.Date) { model.GuestsInside += raport.GuestsIn - raport.GuestsOut; model.GuestsIn += raport.GuestsIn; model.GuestsOut += raport.GuestsOut; } } return(View(model)); }
public HomeController(ILogger <HomeController> logger, GuestCounterContext context, DbContextOptions <GuestCounterContext> dbContextOptions) { _logger = logger; _context = context; _dbContextOptions = dbContextOptions; }