Пример #1
0
        public void TestMethod1()
        {
            var reviewerProvider = new ReviewerProvider();
            var workingDays      = new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday };
            var fromTime         = new TimeSpan(0, 0, 0);
            var toTime           = new TimeSpan(24, 0, 0);
            var allReviwers      = reviewerProvider.GetList();

            foreach (var rvr in allReviwers)
            {
                var isInWorkingHours = rvr.IsInWorkingHours(fromTime, toTime, workingDays);
                Console.WriteLine("{0}: {1}", rvr.Name, isInWorkingHours);
            }
        }
        public ActionResult Index()
        {
            var reviewers     = new ReviewerProvider();
            var jobApplicants = new JobApplicationProvider();


            var avgDurations = jobApplicants.GetList()
                               .GroupBy(rvw => rvw.ReviewerId)
                               .Select(g => new
            {
                g.Key,
                AvgDuration =
                    g.Average(
                        x =>
                        ((x.RejectedOrAcceptedAt ?? DateTime.UtcNow) - x.AssignedToReviewerAt).HasValue
                                    ? Math.Max(
                            ((x.RejectedOrAcceptedAt ?? DateTime.UtcNow) - x.AssignedToReviewerAt).Value
                            .TotalSeconds / 3600, 0)
                                    : 0)
            });

            //var results = reviewers.GetList()
            //    .Join(avgDurations, rvw => rvw.Id, ad => ad.Key, (rvw, ad) => new ReviewerViewModel { Reviewer = rvw, AvgTime = ad.AvgDuration });

            var results = reviewers.GetList()
                          .GroupJoin(avgDurations,
                                     rvw => rvw.Id,
                                     ad => ad.Key,
                                     (rvw, ms) => new { rvw, ms = ms.DefaultIfEmpty() })
                          .SelectMany(
                z => z.ms.Select(ad => new { rvw = z.rvw, ad }))
                          .Select(x => new ReviewerViewModel()
            {
                Reviewer = x.rvw,
                AvgTime  = x.ad == null? 0 : Math.Round(x.ad.AvgDuration, 2)
            });



            return(View(results.ToList()));
        }
        public ActionResult Get()
        {
            var service = new ReviewerProvider();

            return(Json(service.GetList(), JsonRequestBehavior.AllowGet));
        }