Esempio n. 1
0
        public async Task <IHttpActionResult> EmailAll(EmailAllBindingModel model)
        {
            var course = await MailExtensions.GetCourseIncludes(Repo)
                         .FirstOrDefaultAsync(cp => cp.Id == model.CourseId);

            //Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(course.Department.Institution.LocaleCode);

            if (course == null)
            {
                return(NotFound());
            }
            if (course.LastDay().StartFacultyUtc < DateTime.UtcNow)
            {
                return(Ok("The course finish must be after now"));
            }

            var result = await CreateParticipantEmails.SendCourseEmail(course /*, User */, UserManager);

            DateTime now = DateTime.UtcNow;

            foreach (var cp in result.SuccessRecipients)
            {
                cp.EmailedUtc = now;
            }
            await Repo.SaveChangesAsync();

            return(Ok(new
            {
                SuccessRecipients = result.SuccessRecipients.Select(sr => sr.ParticipantId),
                FailRecipients = result.FailRecipients.Select(sr => sr.ParticipantId)
            }));
        }
Esempio n. 2
0
        public void TestCourseInvite()
        {
            Course course;

            using (var context = new MedSimDbContext())
            {
                var courseQueryable = MailExtensions.GetCourseIncludes(context);
                course = courseQueryable.AsNoTracking().First(c => c.CourseParticipants.Any(cp => cp.IsFaculty) && c.CourseParticipants.Any(cp => !cp.IsFaculty));
            }

            WriteMail(new CourseInvite {
                CourseParticipant = course.CourseParticipants.First()
            });
        }