Example #1
0
        public ActionResult Reports()
        {
            try
            {
                var failureRepo       = new FailureRepo();
                var surveyRepo        = new SurveyRepo();
                var failureList       = failureRepo.GetAll(x => x.SurveyId != null).ToList();
                var surveyList        = surveyRepo.GetAll().Where(x => x.IsDone).ToList();
                var totalSpeed        = 0.0;
                var totalTech         = 0.0;
                var totalPrice        = 0.0;
                var totalSatisfaction = 0.0;
                var totalSolving      = 0.0;
                var count             = failureList.Count;

                if (count == 0)
                {
                    TempData["Message"] = "Herhangi bir kayıt bulunamadı.";
                    return(RedirectToAction("Index", "Home"));
                }
                foreach (var survey in surveyList)
                {
                    totalSpeed        += survey.Speed;
                    totalTech         += survey.TechPoint;
                    totalPrice        += survey.Pricing;
                    totalSatisfaction += survey.Satisfaction;
                    totalSolving      += survey.Solving;
                }
                var totalDays = 0;

                foreach (var failure in failureList)
                {
                    if (failure.FinishingTime.HasValue)
                    {
                        totalDays += failure.FinishingTime.Value.DayOfYear - failure.CreatedDate.DayOfYear;
                    }
                }

                ViewBag.AvgSpeed        = totalSpeed / count;
                ViewBag.AvgTech         = totalTech / count;
                ViewBag.AvgPrice        = totalPrice / count;
                ViewBag.AvgSatisfaction = totalSatisfaction / count;
                ViewBag.AvgSolving      = totalSolving / count;
                ViewBag.AvgTime         = totalDays / failureList.Count;

                return(View(surveyList));
            }
            catch (Exception ex)
            {
                TempData["Message"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "Reports",
                    ControllerName = "Admin",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }
Example #2
0
        public JsonResult GetDailyReport()
        {
            try
            {
                var dailyFailures = failureRepo.GetAll(x => x.CreatedDate.DayOfYear == DateTime.Now.DayOfYear).Count;

                return(Json(new ResponseData()
                {
                    data = dailyFailures,
                    success = true
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new ResponseData()
                {
                    data = 0,
                    message = ex.Message,
                    success = false
                }, JsonRequestBehavior.AllowGet));
            }
        }