Ejemplo n.º 1
0
        /// <summary>
        /// Write result to json file
        /// </summary>
        /// <param name="path">path to file</param>
        /// <param name="students">students list</param>
        /// <param name="allAvarage">avarages for all subjects</param>
        public void WriteFile(string fileName, IEnumerable <Student> students, IEnumerable <Subject> allAvarage)
        {
            using var fileStream = new FileStream(string.Concat($"{fileName}.", FileFormat.Json.ToString().DefineFormat()), FileMode.OpenOrCreate);
            var studentList        = ConsoleHelper.StudentToStudentAverageMark(students);
            var json               = new DataContractJsonSerializer(typeof(AverageGroupRating));
            var averageGroupRating = new AverageGroupRating(ConsoleHelper.FindAverageGroupRating(students), studentList, allAvarage);

            json.WriteObject(fileStream, averageGroupRating);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Write result to csv file
        /// </summary>
        /// <param name="path"></param>
        /// <param name="students"></param>
        public void WriteFile(string fileName, IEnumerable <Student> students, IEnumerable <Subject> allAvarage)
        {
            var excelFile = new FileInfo(string.Concat($"{fileName}.", FileFormat.Excel.ToString().DefineFormat()));

            using var package = new ExcelPackage(excelFile);

            var studentsList = ConsoleHelper.StudentToStudentAverageMark(students);

            var avarageGroupRating = new AverageGroupRating(ConsoleHelper.FindAverageGroupRating(students), studentsList, allAvarage.ToList());

            var worksheet = package.Workbook.Worksheets.Add($"{typeof(StudentAverageMark).ToString()}{package.Workbook.Worksheets.Count}");

            worksheet.Cells[1, 1].LoadFromCollection(avarageGroupRating.Students, true);

            int lastRow = worksheet.Dimension.End.Row;

            worksheet.Cells[lastRow + 1, 1].LoadFromCollection(avarageGroupRating.Subjects, true);

            lastRow = worksheet.Dimension.End.Row;

            worksheet.Cells[lastRow + 1, 1].Value = avarageGroupRating.Average;

            package.Save();
        }