/// <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())); } }
/// <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())); } }
/// <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())); } }