public async Task <IActionResult> Detail(int id) { ViewData["TasksCount"] = 0; ViewData["TimeCount"] = 0; ViewData["TasksCountMonth"] = 0; ViewData["TimeCountMonth"] = 0; var result = await _projectFactory.GetObject($"api/project/{id}"); if (result != null) { var tasks = await _taskFactory.GetObjects($"api/task/project/{id}"); ViewData["Tasks"] = tasks; if (tasks != null) { ViewData["TasksCount"] = tasks.Count(); ViewData["TasksCountMonth"] = tasks.Where(x => x.StarDate.Month == DateTime.Now.Month || x.CloseDate != null && x.CloseDate.Value.Month == DateTime.Now.Month).Count(); var times = await _timeFactory.GetObjects($"api/task/project/time/{id}"); if (times != null) { var totalTime = (decimal)times.Sum(x => x.TotalTime); ViewData["TimeCount"] = decimal.Round(totalTime, 2, MidpointRounding.AwayFromZero); var totalTimeMonth = (decimal)times.Where(x => x.Start.Month == DateTime.Now.Month && x.Close.Value.Month == DateTime.Now.Month).Sum(x => x.TotalTime); ViewData["TimeCountMonth"] = decimal.Round(totalTimeMonth, 2, MidpointRounding.AwayFromZero); } } } return(View(result)); }