Esempio n. 1
0
        /// <summary>
        /// Complete Enrolled Module
        /// </summary>
        /// <param name="input">Object of Enrollem Module Model</param>
        /// <returns>Result of Update an enrolled module</returns>
        public async Task <OutputResult> CompleteEnrolledModule(Input <EnrollModuleModel> input)
        {
            try
            {
                // Input Validation
                if (!input.Validate)
                {
                    return(OutputResult.FailOutputResult(Constant.InvalidInput));
                }

                // Varciable Init
                var model = input.Arguments;

                // Retrive Entities
                var enrollment = UnitOfWork.Enrollments.GetEnrollModule(model.ModuleId, model.EnrollmentId);

                // Process Entities
                enrollment.IsCompleted = true;
                enrollment.LastVisited = DateTime.Now;

                // Commit Transaction
                await UnitOfWork.Commit();

                // Retrun Success Output
                return(OutputResult.SuccessOutputResult());
            }
            catch (Exception exception)
            {
                // Failed Output in case of exception
                return(OutputResult.FailOutputResult(Constant.ErrorOccured, description: exception.ToString()));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Add an enrollment
        /// </summary>
        /// <param name="input">Object of Enrollment Model</param>
        /// <returns>Result of Adding an enrollment</returns>
        public async Task <OutputResult> AddEnrollment(Input <EnrollmentModel> input)
        {
            try
            {
                // Input validate
                if (!input.Validate)
                {
                    return(OutputResult.FailOutputResult(Constant.InvalidInput));
                }

                // Variable init
                var datetime = DateTime.UtcNow;
                var model    = input.Arguments;

                // Retrive Entities
                var enrollment = UnitOfWork.Enrollments.FirstOrDefault(e => e.StudentId == model.StudentId & e.CourseId == model.CourseId);

                // Validate ENtities
                if (enrollment != null)
                {
                    return(OutputResult.FailOutputResult(Constant.AlreadyEnrolled));
                }

                // Process Entities
                var enrollmentId  = Generator.UniqueIdentifier;
                var course        = UnitOfWork.Courses.GetCourse(model.CourseId);
                var enrollModules = course.Modules.Select(m => new Entities.EnrollModule
                {
                    ModuleId     = m.Id,
                    EnrollmentId = enrollmentId,
                    IsCompleted  = false,
                    IsStarted    = false
                }).ToList();

                // Adding Enrollment
                UnitOfWork.Enrollments.Add(new Entities.Enrollment
                {
                    Id            = enrollmentId,
                    CreateBy      = input.OperationBy,
                    UpdateBy      = input.OperationBy,
                    CreateDate    = datetime,
                    UpdateDate    = datetime,
                    CourseId      = model.CourseId,
                    StudentId     = model.StudentId,
                    EnrollModules = enrollModules
                });

                // Commit Transaction
                await UnitOfWork.Commit();

                // Success Output
                return(OutputResult.SuccessOutputResult());
            }
            catch (Exception exception)
            {
                // Failed Output in case of exception
                return(OutputResult.FailOutputResult(Constant.ErrorOccured, description: exception.ToString()));
            }
        }
Esempio n. 3
0
 public JsonResult VerifyStudent([FromBody] StudentModel studentModel)
 {
     try
     {
         return(Json(StudentService.VerifyStudent(new Input <StudentModel> {
             Arguments = studentModel
         })));
     }
     catch (Exception exception)
     {
         return(Json(OutputResult.FailOutputResult(exception.Message)));
     }
 }
Esempio n. 4
0
 public JsonResult CompleteEnrollModule([FromBody] EnrollModuleModel enrollModuleModel)
 {
     try
     {
         return(Json(EnrollmentService.CompleteEnrolledModule(new Input <EnrollModuleModel>
         {
             OperationBy = "System",
             Arguments = enrollModuleModel
         })));
     }
     catch (Exception exception)
     {
         return(Json(OutputResult.FailOutputResult(exception.Message)));
     }
 }
Esempio n. 5
0
 public JsonResult EnrollCourse([FromBody] EnrollmentModel enrollmentModel)
 {
     try
     {
         return(Json(EnrollmentService.AddEnrollment(new Input <EnrollmentModel>
         {
             OperationBy = "System",
             Arguments = new EnrollmentModel
             {
                 CourseId = enrollmentModel.CourseId,
                 StudentId = enrollmentModel.StudentId
             }
         })));
     }
     catch (Exception exception)
     {
         return(Json(OutputResult.FailOutputResult(exception.Message)));
     }
 }
Esempio n. 6
0
        public JsonResult AddCourse([FromBody] AddCourseModel courseModel)
        {
            try
            {
                // Convert Model to Data Transafer Object Model which accept in Add Course Method
                var moduleModelDto = new List <ModuleModel>();
                courseModel.Modules
                .OrderBy(m => m.Order)
                .ToList()
                .ForEach(m =>
                {
                    if (m.Icon == "TEXT")
                    {
                        moduleModelDto.Add(new TextModuleModel
                        {
                            Title       = m.Title,
                            Description = m.Description,
                            CanSkip     = m.CanSkip
                        });
                    }

                    if (m.Icon == "VIDEO")
                    {
                        moduleModelDto.Add(new VideoModuleModel
                        {
                            Title    = m.Title,
                            CanSkip  = m.CanSkip,
                            Uri      = m.Uri,
                            Duration = new System.TimeSpan(0, 0, 0)
                        });
                    }

                    if (m.Icon == "QUESTION")
                    {
                        moduleModelDto.Add(new QuestionModuleModel
                        {
                            Title   = m.Title,
                            CanSkip = m.CanSkip,
                            Text    = m.Text,
                            Choices = m.Choices
                        });
                    }
                });

                var courseModelDto = new CourseModel
                {
                    Subject     = courseModel.Subject,
                    Description = courseModel.Description,
                    Modules     = moduleModelDto
                };

                return(Json(CourseService.AddCourse(new Input <CourseModel>
                {
                    OperationBy = "System",
                    Arguments = courseModelDto
                })));
            }
            catch (Exception exception)
            {
                return(Json(OutputResult.FailOutputResult(exception.Message)));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Add a course
        /// </summary>
        /// <param name="input">Object of Course Model</param>
        /// <returns>Result of adding a course</returns>
        public async Task <OutputResult> AddCourse(Input <CourseModel> input)
        {
            try
            {
                // Input validate
                if (!input.Validate)
                {
                    return(OutputResult.FailOutputResult(Constant.InvalidInput));
                }

                // Variable init
                var datetime = DateTime.UtcNow;
                var model    = input.Arguments;
                var modules  = new List <Entities.Module>();

                // Model process
                model.Modules.ForEach(m =>
                {
                    if (m is VideoModuleModel)
                    {
                        var video = m as VideoModuleModel;
                        modules.Add(new Entities.Video
                        {
                            Id         = Generator.UniqueIdentifier,
                            CreateBy   = input.OperationBy,
                            UpdateBy   = input.OperationBy,
                            CreateDate = datetime,
                            UpdateDate = datetime,
                            CanSkip    = video.CanSkip,
                            Icon       = video.Icon,
                            Title      = video.Title,
                            Uri        = video.Uri,
                            Duration   = video.Duration
                        });
                    }

                    if (m is TextModuleModel)
                    {
                        var text = m as TextModuleModel;
                        modules.Add(new Entities.Text
                        {
                            Id          = Generator.UniqueIdentifier,
                            CreateBy    = input.OperationBy,
                            UpdateBy    = input.OperationBy,
                            CreateDate  = datetime,
                            UpdateDate  = datetime,
                            CanSkip     = text.CanSkip,
                            Icon        = text.Icon,
                            Title       = text.Title,
                            Description = text.Description
                        });
                    }

                    if (m is QuestionModuleModel)
                    {
                        var question = m as QuestionModuleModel;
                        modules.Add(new Entities.Question
                        {
                            Id         = Generator.UniqueIdentifier,
                            CreateBy   = input.OperationBy,
                            UpdateBy   = input.OperationBy,
                            CreateDate = datetime,
                            UpdateDate = datetime,
                            CanSkip    = question.CanSkip,
                            Icon       = question.Icon,
                            Title      = question.Title,
                            Text       = question.Text,
                            Choices    = question.Choices.Select(c => new Entities.Choice
                            {
                                IsAnswer = c.IsAnswer,
                                Option   = c.Option
                            }).ToList()
                        });
                    }
                    ;
                });

                // Course Adding
                UnitOfWork.Courses.Add(new Entities.Course
                {
                    Id          = Generator.UniqueIdentifier,
                    CreateBy    = input.OperationBy,
                    UpdateBy    = input.OperationBy,
                    CreateDate  = datetime,
                    UpdateDate  = datetime,
                    Subject     = model.Subject,
                    Description = model.Description,
                    Modules     = modules
                });

                // Commit Transaction
                await UnitOfWork.Commit();

                // Success Output
                return(OutputResult.SuccessOutputResult());
            }
            catch (Exception exception)
            {
                // Failed Output in case of exception
                return(OutputResult.FailOutputResult(Constant.ErrorOccured, description: exception.ToString()));
            }
        }