Esempio n. 1
0
        public IActionResult Download(int locationId)
        {
            var users =
                from user in dbContext.Users.Include(u => u.Roles).Include(u => u.UserSubscriptions)
                where user.EmailConfirmed
                join userRole in dbContext.UserRoles on user.Id equals userRole.UserId
                join role in dbContext.Roles on userRole.RoleId equals role.Id
                where role.Name == Roles.User
                select user;

            var threshold = DateTime.Today.AddDays(-14);

            var absentUsers =
                from user in users.Include(u => u.Schedules).ThenInclude(s => s.Timetable).ThenInclude(t => t.Course)
                where !user.Schedules.Any(s => s.Date > threshold)
                where user.Schedules.Any(s => s.Timetable.LocationId == locationId)
                let lastTime = (
                    from schedule in user.Schedules
                    where schedule.Timetable.LocationId == locationId
                    orderby schedule.Date descending
                    select schedule).FirstOrDefault()
                               let userSubs =
                    from sub in user.UserSubscriptions
                    select sub.Subscription.CourseType.Name
                    let typesPastTwoWeeks = (
                        from schedule in user.Schedules
                        where schedule.Timetable.LocationId == locationId
                        where schedule.Date > threshold
                        select schedule.Timetable.Course.CourseType.Name).Distinct()
                                            let courseTypes = userSubs.Except(typesPastTwoWeeks)
                                                              select new
            {
                Voornaam   = user.FirstName,
                Achternaam = user.LastName,
                Telefoon   = user.PhoneNumber,
                user.Email,
                LaatsteKeer        = lastTime == null ? string.Empty : lastTime.Date.ToString("dd-MM-yyyy"),
                Begeleidingsvormen = string.Join(", ", courseTypes)
            };

            var bytes = csvWriter.WriteRecords(absentUsers);

            return(File(bytes, "text/csv", "afwezigen.csv"));
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public void Load(List <COReDataRecord> data)
        {
            if (!Directory.Exists(this.folderPath))
            {
                throw new ArgumentException("Dir path was not found");
            }

            if (data == null)
            {
                throw new Exception("DataRecord was not found, did you call CreateDataRecord()?");
            }

            string filePath = Path.Combine(folderPath, constructFileName(data.Last()));

            using (var file = File.CreateText(filePath))
            {
                writer = new CsvHelper.CsvWriter(file);
                writer.WriteRecords(data);
            }
        }