Example #1
0
        public async Task <ActionResult> InviteLearners(InviteLearnerModel model)
        {
            var response = await WepApiMethod.SendApiAsync <InviteLearnerModel>(HttpVerbs.Post,
                                                                                CourseEventApiUrl.InviteLearners, model);

            if (response.isSuccess)
            {
                await LogActivity(Modules.Learning, $"Success invite learner - Course - {model.CourseTitle}, Enrollment Code - {model.EnrollmentCode}");

                TempData["SuccessMessage"] = "An invitation will be sent to the listed emails.";

                // -- send email
                await Notifier.SendEnrollmentInvitationByListOfEmails(NotificationType.Course_Invitation,
                                                                      model.CourseEventId, CurrentUser.UserId.Value,
                                                                      model.LearnerEmails, model.CreatedBy, model.CourseTitle, Url.AbsoluteAction("View", "Courses",
                                                                                                                                                  new { id = model.CourseId, enrollmentCode = model.EnrollmentCode }));
            }
            else
            {
                await LogError(Modules.Learning, $"Error inviting learners - Course - {model.CourseId}");

                TempData["ErrorMessage"] = "Error inviting learners to the course.";
            }

            return(RedirectToAction("Content", "Courses", new { area = "eLearning", id = model.CourseId }));
        }
Example #2
0
        public async Task <ActionResult> InviteMoreLearners(int eventId, string title)
        {
            var createdBy = CurrentUser.UserId;

            var courseEvent = await TryGetCourseEvent(eventId);

            if (courseEvent != null)
            {
                var model = new InviteLearnerModel
                {
                    CourseId       = courseEvent.CourseId,
                    CourseEventId  = eventId,
                    EnrollmentCode = courseEvent.EnrollmentCode,
                    CourseTitle    = title
                };

                return(View("InviteLearners", model));
            }
            else
            {
                TempData["ErrorMessage"] = $"Cannot get the event.";

                return(Redirect(Request.UrlReferrer.ToString()));
            }
        }
        public async Task <IHttpActionResult> InviteLearners(InviteLearnerModel model)
        {
            if (ModelState.IsValid)
            {
                var courseEvent = await db.CourseEvents.FindAsync(model.CourseEventId);

                if (courseEvent == null)
                {
                    return(BadRequest("No course event found"));
                }

                if (String.IsNullOrEmpty(model.LearnerEmails))
                {
                    return(BadRequest("No emails found."));
                }

                var emails = model.LearnerEmails.Split(',');

                foreach (var email in emails)
                {
                    db.CourseInvitations.Add(new CourseInvitation
                    {
                        CourseId         = model.CourseId,
                        CourseEventId    = model.CourseEventId,
                        NotificationType = NotificationType.Course_Invitation,
                        CreatedBy        = int.Parse(model.CreatedBy),
                        Emails           = email,
                    });
                }
                await db.SaveChangesAsync();
            }
            return(Ok());
        }
Example #4
0
        public ActionResult InviteLearners(int courseId, int eventId, string enrollmentCode = "", string title = "")
        {
            var createdBy = CurrentUser.UserId;

            var model = new InviteLearnerModel
            {
                CourseId       = courseId,
                CourseEventId  = eventId,
                EnrollmentCode = enrollmentCode,
                CourseTitle    = title
            };

            var courseEvent = db.CourseEvents.FirstOrDefault(x => x.Id == eventId);

            if (courseEvent != null)
            {
                model.EnrollmentCode = courseEvent.EnrollmentCode;
                model.CourseTitle    = courseEvent.Course.Title;
            }

            return(View(model));
        }