Пример #1
0
        public async Task <ActionResult> AddUser(int CourseId, int[] Ids)
        {
            var model = new UpdateTrainerCourseModel
            {
                CourseId = CourseId,
                UserId   = Ids.ToList()
            };

            var response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, $"eLearning/Courses/AddUser", model);

            if (response.isSuccess)
            {
                TempData["SuccessMessage"] = "User successfully assigned to role trainer/instructor.";
                await LogActivity(Modules.Learning, "Assign user to trainer", model);

                // Notification
                var notifyModel = new NotificationModel
                {
                    Id                    = CourseId,
                    Type                  = typeof(Course),
                    NotificationType      = NotificationType.Course_Assigned_To_Facilitator,
                    NotificationCategory  = NotificationCategory.Learning,
                    StartNotificationDate = DateTime.Now,
                    ParameterListToSend   = new ParameterListToSend
                    {
                        Link = this.Url.AbsoluteAction("View", "Courses", new { id = CourseId }),
                    },
                    ReceiverType    = ReceiverType.UserIds,
                    Receivers       = Ids.ToList(),
                    IsNeedRemainder = false,
                };

                var emailResponse = await EmaiHelper.SendNotification(notifyModel);

                if (emailResponse == null || String.IsNullOrEmpty(emailResponse.Status) ||
                    !emailResponse.Status.Equals("Success", System.StringComparison.OrdinalIgnoreCase))
                {
                    await LogError(Modules.Learning, $"Error Sending Email For Facilitator When Assigned to A Course. Course Id : {CourseId}");
                }
            }
            else
            {
                TempData["ErrorMessage"] = "Fail to assign role.";
            }

            return(RedirectToAction("Trainers", "Courses", new { area = "eLearning", id = CourseId }));
        }
        public async Task <ActionResult> EnrollAsync(int courseId, string enrollmentCode = "")
        {
            var currentUserId = CurrentUser.UserId.Value;

            WebApiResponse <bool> response = null;

            if (String.IsNullOrEmpty(enrollmentCode))
            {
                response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Get,
                                                                  CourseApiUrl.IsUserEnrolled + $"?id={courseId}&userId={currentUserId}");
            }
            else
            {
                response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Get,
                                                                  CourseApiUrl.IsUserEnrolled + $"?id={courseId}&userId={currentUserId}&enrollmentCode={enrollmentCode}");
            }

            if (response.isSuccess)
            {
                //if (response.Data == false) // testing fix - CONTINuE FIX HERE
                if (response.Data == true)
                {
                    TempData["ErrorMessage"] = "You are already enrolled to this course.";

                    return(RedirectToAction("View", "Courses", new { area = "eLearning", id = courseId, enrollmentCode = enrollmentCode }));
                }
            }

            var enrollResponse = new WebApiResponse <TrxResult <Enrollment> >();

            if (String.IsNullOrEmpty(enrollmentCode))
            {
                enrollResponse = await WepApiMethod.SendApiAsync <TrxResult <Enrollment> >(HttpVerbs.Get,
                                                                                           CourseEnrollmentApiUrl.EnrollAsync + $"?id={courseId}&userId={currentUserId}");
            }
            else
            {
                enrollResponse = await WepApiMethod.SendApiAsync <TrxResult <Enrollment> >(HttpVerbs.Get,
                                                                                           CourseEnrollmentApiUrl.EnrollAsync + $"?id={courseId}&userId={currentUserId}&enrollmentCode={enrollmentCode}");
            }

            if (enrollResponse.isSuccess)
            {
                var result = enrollResponse.Data;

                if (result.IsSuccess)
                {
                    await LogActivity(Modules.Learning, Gamification.UserEnrolled.ToString(), $"User {currentUserId} enrolled to the course {courseId} with" +
                                      $" enrollment code - {enrollmentCode} ");

                    TempData["SuccessMessage"] = "You are now enrolled to this course.";

                    // Notification
                    var notifyModel = new NotificationModel
                    {
                        Id                    = courseId,
                        Type                  = typeof(Course),
                        NotificationType      = NotificationType.Course_Student_Enrolled,
                        NotificationCategory  = NotificationCategory.Learning,
                        StartNotificationDate = DateTime.Now,
                        ParameterListToSend   = new ParameterListToSend
                        {
                            Link = this.Url.AbsoluteAction("View", "Courses", new { id = courseId }),
                        },

                        SenderId        = currentUserId,
                        ReceiverType    = ReceiverType.UserIds,
                        IsNeedRemainder = false,
                    };

                    var emailResponse = await EmaiHelper.SendNotification(notifyModel);

                    if (emailResponse == null || String.IsNullOrEmpty(emailResponse.Status) ||
                        !emailResponse.Status.Equals("Success", System.StringComparison.OrdinalIgnoreCase))
                    {
                        await LogError(Modules.Learning, $"Error Sending Email For Facilitator When A Student Enrolled. Course Id : {courseId}");
                    }

                    // firus start
                    var responseInput = await WepApiMethod.SendApiAsync <CourseAdditionalInputModel>(HttpVerbs.Get, CourseApiUrl.GetAdditionalInput + $"?id={courseId}&coursetitle=");

                    if (responseInput.isSuccess)
                    {
                        var inputmodel = responseInput.Data;
                        return(RedirectToAction("AdditionalInput", "CourseEnrollments", new { area = "eLearning", id = courseId, enrollmentCode = enrollmentCode }));
                    }
                    else
                    {
                        return(RedirectToAction("View", "Courses", new { area = "eLearning", id = courseId, enrollmentCode = enrollmentCode }));
                    }
                    // firus end

                    //return RedirectToAction("View", "Courses", new { area = "eLearning", id = courseId, enrollmentCode = enrollmentCode });
                }
            }

            await LogError(Modules.Learning, "User Enrolled Failed ", $"User {currentUserId} failed to enroll to the course {courseId} with" +
                           $" enrollment code - {enrollmentCode}. Error - {enrollResponse.Data.Message}");

            TempData["ErrorMessage"] = "Error enrolling to the course." + enrollResponse.Data.Message;

            return(RedirectToAction("View", "Courses", new { area = "eLearning", id = courseId, enrollmentCode = enrollmentCode }));
        }