コード例 #1
0
        public MedicationUsageReport GenerateMedicationUsageReport(Period period)
        {
            char sep = Path.DirectorySeparatorChar;
            MedicationUsageReport report = new MedicationUsageReport(period.StartTime, period.EndTime);
            string filepath = "." + sep + "GeneratedUsageReports" + sep + report.Id + ".json";
            List <MedicationUsage> usages = _medicationUsageRepository.GetAll().ToList()
                                            .Where(ur => ur.InPeriod((DateTime)report.From, (DateTime)report.Until)).ToList();

            report.MedicationUsages.AddRange(usages);

            var jsonResolver       = new MedicationUsageReportContractResolver();
            var serializerSettings = new JsonSerializerSettings();

            serializerSettings.ContractResolver = jsonResolver;
            string json = JsonConvert.SerializeObject(report);

            Console.WriteLine(json);
            JsonSerializer jsonSerializer = new JsonSerializer();

            using (StreamWriter swriter = new StreamWriter(filepath))
                using (JsonWriter jwriter = new JsonTextWriter(swriter))
                {
                    jsonSerializer.Serialize(jwriter, report);
                }
            return(Add(report));
        }
コード例 #2
0
 public List <MedicationUsage> GetAll() => _medicationUsageRepository.GetAll();