Esempio n. 1
0
        public static (int, IQueryable <Health>) Search(DatabaseContext context, bool isInfected, EnvironmentVariableService ev, int courseId, string filterString, int?page = null, int?numPerPage = null)
        {
            var course   = context.Courses.Include(x => x.StudentAssignments).ThenInclude(x => x.Student).Where(x => x.Id == courseId).FirstOrDefault();
            var students = course.StudentAssignments.Select(x => x.Student.Account);

            var fc = new FilterCompiler(filterString);

            return(fc.Filtering(context, isInfected, courseId, ev.GetTimeFrames(), course.StartDate, course.NumOfDaysToSearch));
        }
Esempio n. 2
0
        public IActionResult CsvFile(string courseId, [FromQuery] string filterString)
        {
            Console.WriteLine($"courseId: {courseId}");
            Console.WriteLine($"filterString: {filterString}");
            var pathBase = HttpContext.Request.PathBase.HasValue ? HttpContext.Request.PathBase.Value : "";

            if (!int.TryParse(courseId, out var id))
            {
                return(new NotFoundResult());
            }
            var staff = DB.Context.Staffs.Where(x => x.Account == HttpContext.User.Identity.Name).FirstOrDefault();

            if (staff == null)
            {
                return(new NotFoundResult());
            }
            var isTestMode = !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TEST_MODE"));
            var course     = DB.Context.Courses.ToArray().Where(x => x.Id == id && (isTestMode || staff.IsAdmin || x.AssignedStaffAccounts().Contains(HttpContext.User.Identity.Name))).FirstOrDefault();

            if (course == null)
            {
                return(new NotFoundResult());
            }

            var(count, list) = Health.Search(DB.Context, false, EV, course.Id, filterString ?? "");
            byte[] result;
            using (var ms = new MemoryStream())
            {
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

                var tfs           = EV.GetTimeFrames();
                var hasTimeFrames = tfs != null?EV.GetTimeFrames()?.Count() > 0 : false;

                using (var w = new StreamWriter(ms, Encoding.GetEncoding("Shift_JIS")))
                {
                    w.Write("観察者番号,");
                    w.Write("名前,");
                    w.Write("日付,");
                    if (hasTimeFrames)
                    {
                        w.Write("時間帯,");
                    }
                    w.Write("体温,");
                    w.Write("せき,");
                    w.Write("息苦しさ,");
                    w.Write("鼻水,");
                    w.Write("のどの痛み,");
                    w.Write("体のだるさ,");
                    w.Write("下痢,");
                    w.Write("頭痛,");
                    w.Write("その他風邪症状,");
                    w.Write("その他症状詳細,");
                    w.Write("解熱剤・せき止め薬・かぜ薬等の服用,");
                    w.Write("検査実施,");
                    w.Write("検査結果,");
                    w.WriteLine();
                    foreach (var health in list.Where(x => !x.IsInfected))
                    {
                        w.Write($"{health.Student.Account},");
                        w.Write($"{health.Student.Name},");
                        w.Write($"{health.MeasuredAt.ToShortDateString()},");
                        if (hasTimeFrames)
                        {
                            w.Write($"{health.TimeFrame},");
                        }
                        if (health.IsEmptyData)
                        {
                            w.Write($",,,,,,,,,,,,,");
                        }
                        else
                        {
                            w.Write($"{health.BodyTemperature},");
                            w.Write($"{health.StringColumn1},");
                            w.Write($"{health.StringColumn2},");
                            w.Write($"{health.StringColumn3},");
                            w.Write($"{health.StringColumn4},");
                            w.Write($"{health.StringColumn5},");
                            w.Write($"{health.StringColumn6},");
                            w.Write($"{health.StringColumn7},");
                            w.Write($"{health.StringColumn8},");
                            w.Write($"{health.StringColumn9},");
                            w.Write($"{health.StringColumn10},");
                            w.Write($"{health.StringColumn11},");
                            w.Write($"{health.StringColumn12},");
                        }
                        w.WriteLine();
                    }
                }
                result = ms.ToArray();
            }
            return(File(result, "text/csv"));
        }