public UserCourse CreateCourse(int userId, int topicId, int nTasks, int durationDays) { if (database.UserCourses.Find(c => c.UserId == userId && c.EndDate > DateTime.Now).Count() > 0) { throw new Exception("User has unfinished course."); } var newUserCourse = new UserCourse { UserId = userId, EndDate = DateTime.Now.AddDays(durationDays) }; var tasksForTopic = database.Tasks.Find(t => t.TopicId == topicId).ToList(); var rand = new Random(); for (int i = 0; i < nTasks; ++i) { var randomTask = tasksForTopic[rand.Next(0, tasksForTopic.Count)]; tasksForTopic.Remove(randomTask); var newCourseTask = new CourseTask { TaskId = randomTask.Id, CompPer = 0 }; newUserCourse.CourseTasks.Add(newCourseTask); } database.UserCourses.Create(newUserCourse); database.Save(); return(newUserCourse); }
private void btnCourseStart_Click(object sender, EventArgs e) { CourseTask ct = new CourseTask(); ct.CourseId = 5; ct.Master = new CardInfo { Rfid = "1234567", No = "0001", Name = "张三" }; ct.Assistant1 = new CardInfo { Rfid = "1234568", No = "0002", Name = "李四" }; ct.Assistant2 = new CardInfo { Rfid = "1234569", No = "0003", Name = "王五" }; //xuesheng ct.Students.Add(new CardInfo { Rfid = "C23456A", No = "JQ00002", Name = "张小虎" }); ct.Students.Add(new CardInfo { Rfid = "D23456B", No = "JQ00003", Name = "李小龙" }); long id = StoreModel.StartCourseTask(ct); AddLog("id=" + id.ToString()); temp_id = id; temp_course_task = ct; }
internal static long StartCourseTask(CourseTask ct) { //课程允许开课 //准备好教师和学生数据 long?master_id = PrepareTeacher(ct.Master); long?assistant1_id = PrepareTeacher(ct.Assistant1); long?assistant2_id = PrepareTeacher(ct.Assistant2); //main table insert string sql = "insert into course_task (begin_time,status,master_id,assistant1_id,assistant2_id,status,course_id) values( datetime('now','localtime'),?,?,?,?,?,?)"; SqlLiteHelper.ExecuteNonQuery(sql, CourseTask.STATUS_START, master_id, assistant1_id, assistant2_id, CourseTask.STATUS_START, ct.CourseId); //student? object result = SqlLiteHelper.ExecuteScalar("SELECT last_insert_rowid()"); //get id = result; //to students table ; List <long> students = PrepareStudents(ct.Students); //insert students sql = "insert into course_task_student (course_task_id,student_id) values(?,?)"; foreach (long sid in students) { SqlLiteHelper.ExecuteNonQuery(sql, result, sid); } return((long)result); }
public ActionResult Create([FromBody] CourseTask review) { Guid userId = Guid.Parse(User.Identity.Name); _courseTaskService.Create(review, userId); return(Ok()); }
public async Task HandleAsync(CourseTaskCreateCommand command) { CourseTask courseTask = new CourseTask() { CourseId = command.CourseId, CreatedById = command.CreatedById, Title = command.Title, Description = command.Description, SubmittedAt = DateTime.Now, DueDate = command.DueDate, GradeMaximum = command.MaximumGrade }; await _context.CourseTask.AddAsync(courseTask); await _context.SaveChangesAsync(); if (command.Files != null) { List <tvz2api_cqrs.Models.File> newFiles = new List <tvz2api_cqrs.Models.File>(); foreach (var file in command.Files) { using (var ms = new MemoryStream()) { file.CopyTo(ms); var fileBytes = ms.ToArray(); var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); fileName = fileName.Substring(0, fileName.LastIndexOf(".")) + fileName.Substring(fileName.LastIndexOf(".")).ToLower(); newFiles.Add(new tvz2api_cqrs.Models.File { Name = Path.GetFileName(fileName), ContentType = file.ContentType, Data = fileBytes, Size = fileBytes.Length }); } } await _context.File.AddRangeAsync(newFiles); await _context.SaveChangesAsync(); newFiles.ForEach(x => { _context.CourseTaskAttachment.Add(new CourseTaskAttachment() { FileId = x.Id, CourseTaskId = courseTask.Id }); }); } await _context.SaveChangesAsync(); }
public CourseTask Create(CourseTask courseTask, Guid executorId) { if (courseTask.AuthorId != executorId) { throw new ArgumentException("Other id marked as author"); } _context.Add(courseTask); _context.SaveChanges(); return(courseTask); }
public async Task HandleAsync(CourseTaskUpdateCommand command) { CourseTask courseTask = await _context .CourseTask .Include(x => x.CourseTaskAttachment) .FirstOrDefaultAsync(x => x.Id == command.Id); courseTask.Title = command.Title; courseTask.Description = command.Description; courseTask.DueDate = command.DueDate; courseTask.GradeMaximum = command.MaximumGrade; _context.CourseTaskAttachment.RemoveRange(courseTask.CourseTaskAttachment); if (command.Files != null) { List <tvz2api_cqrs.Models.File> newFiles = new List <tvz2api_cqrs.Models.File>(); foreach (var file in command.Files) { using (var ms = new MemoryStream()) { file.CopyTo(ms); var fileBytes = ms.ToArray(); var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); fileName = fileName.Substring(0, fileName.LastIndexOf(".")) + fileName.Substring(fileName.LastIndexOf(".")).ToLower(); newFiles.Add(new tvz2api_cqrs.Models.File { Name = Path.GetFileName(fileName), ContentType = file.ContentType, Data = fileBytes, Size = fileBytes.Length }); } } await _context.File.AddRangeAsync(newFiles); await _context.SaveChangesAsync(); newFiles.ForEach(x => { _context.CourseTaskAttachment.Add(new CourseTaskAttachment() { FileId = x.Id, CourseTaskId = courseTask.Id }); }); } await _context.SaveChangesAsync(); }
public void AddTask(CourseTask task, int id) { var course = this.coursesRepository.GetById(id); if (course == null) { return; } course.Tasks.Add(task); this.coursesRepository.Update(course); this.coursesRepository.Save(); }
public async Task <Guid> AddTask(Guid courseId, CourseTask task) { task.Id = Guid.NewGuid(); var taskId = await taskService.Save(task).ConfigureAwait(false); await using var conn = new NpgsqlConnection(ConnectionString); await conn.ExecuteAsync( $@"insert into {PgSchema.course_tasks} (course_id, task_id) values (@CourseId, @TaskId)", new { courseId, taskId }).ConfigureAwait(false); return(taskId); }
public static Review Review(Guid authorId, Guid solutionId, CourseTask courseTask) { return(new Review { AuthorId = authorId, SolutionId = solutionId, PostTime = DateTime.Now, Evaluations = courseTask.Criterias.Select(c => new ReviewCriteria() { CriteriaId = c.Id, Description = GenerateString(), Rating = Random.Next(100), }).ToList() }); }
private void SaveCourseFiles(long courseTaskId, CourseTask ct) { FrmCapture frmCapture = new FrmCapture(); frmCapture.CourseTaskId = courseTaskId; frmCapture.Students = ct.Students; if (frmCapture.ShowDialog() == DialogResult.OK) { //result /*foreach (var item in frmCapture.Photos) * { * AddLog(item.Key + "=" + item.Value); * }*/ StoreModel.FinishCourseTask(courseTaskId, frmCapture.Photos); } }
public void GetTaskSolution() { Guid userId = InstanceFactory.AuthorizedUserId(); Course course = InstanceFactory.Course(); course = _courseService.Create(course, userId); CourseTask courseTask = InstanceFactory.CourseTask(userId, course.Id); courseTask = _courseTaskService.Create(courseTask, userId); CourseSolution solution = InstanceFactory.Solution(userId, courseTask.Id); solution = _solutionService.Create(solution, userId); ICollection <CourseSolution> solutions = _solutionService.GetSolutionsByTask(courseTask.Id, userId); Assert.IsNotNull(solutions); Assert.AreEqual(1, solutions.Count(s => s.AuthorId == userId)); }
public async Task RateSolution([FromQuery] Guid studentId, [FromBody] CourseTask task) => await taskService.RateSolution(studentId, task).ConfigureAwait(false);
public async Task Run() { var cookies = new CookieContainer(); var handler = new HttpClientHandler { CookieContainer = cookies }; httpClient = new HttpClient(handler) { BaseAddress = new Uri("http://*****:*****@tardis.space", Password = "******", Surname = "Doctor", FirstName = "Who", SecondName = "Tardis", Role = UserRole.Admin }; //var authResult = Post<AuthResult>("signUp", doctorWho, HttpStatusCode.OK); Post <AuthResult>("signUp", doctorWho, HttpStatusCode.Conflict); var authData = new AuthData { Email = "*****@*****.**", Password = "******" }; var authResult = Post <AuthResult>("signIn", authData, HttpStatusCode.OK); authResult.Should().NotBeNull(); //authResult.Fio.Should().Be("Doctor W. T."); authResult.Role.Should().Be(UserRole.Admin); authResult.UserId.Should().NotBeEmpty(); var doctorWhoId = authResult.UserId; Get <Course>($"course/get?id={Guid.NewGuid()}", HttpStatusCode.NotFound); var course = new Course { Name = "Space-Time travelling", DescriptionText = "Geronimo!", MaxScore = 1000 }; var courseId = Post <Guid>("course/save", course, HttpStatusCode.OK); courseId.Should().NotBeEmpty(); course.Id = courseId; Get <Course>($"course/get?id={courseId}", HttpStatusCode.OK).Should().BeEquivalentTo(course); var courseTask = new CourseTask { Name = "Find Gallifrey!", DescriptionText = "It is somewhere else", Deadline = DateTime.Now, MaxScore = 100, RequirementList = new[] { new RequirementStatus { Text = "Find Doctor!" } } }; var taskId = Post <Guid>($"course/addTask?courseId={courseId}", courseTask, HttpStatusCode.OK); taskId.Should().NotBeEmpty(); courseTask.Id = taskId; Get <Course>($"task/get?id={taskId}", HttpStatusCode.OK).Should().BeEquivalentTo(courseTask); Post <object>($"task/delete?id={taskId}", null, HttpStatusCode.OK); Get <Course>($"task/get?id={courseId}", HttpStatusCode.NotFound); Post <object>($"course/delete?id={courseId}", null, HttpStatusCode.OK); Get <Course>($"course/get?id={courseId}", HttpStatusCode.NotFound); }
internal static CourseTask GetById(long id) { string sql = @"select ct.*,m.teacher_no as masterNo,m.teacher_name as masterName,m.teacher_rfid as masterRfid, a1.teacher_no as a1No,a1.teacher_name as a1Name,a1.teacher_rfid as a1Rfid, a2.teacher_no as a2No,a2.teacher_name as a2Name,a2.teacher_rfid as a2Rfid, c.course_no from course_task ct left join teacher m on m.teacher_id = ct.master_id left join teacher a1 on a1.teacher_id = ct.assistant1_id left join teacher a2 on a2.teacher_id = ct.assistant2_id ,course c where ct.course_task_id=? and c.course_id=ct.course_id"; var ds = SqlLiteHelper.ExecuteQuery(sql, id); CourseTask ct = new CourseTask(); ct.Id = id; foreach (DataRow row in ds.Tables[0].Rows) { DateTime beginTime = (DateTime)row["begin_time"]; DateTime endTime = (DateTime)row["end_time"]; ct.CourseNo = row["course_no"].ToString(); ct.Master = new CardInfo { No = row["masterNo"].ToString(), Name = row["masterName"].ToString(), Rfid = row["masterRfid"].ToString() }; ct.Assistant1 = new CardInfo { No = row["a1No"].ToString(), Name = row["a1Name"].ToString(), Rfid = row["a1Rfid"].ToString() }; if (!row.IsNull("a2No")) { ct.Assistant2 = new CardInfo { No = row["a2No"].ToString(), Name = row["a2Name"].ToString(), Rfid = row["a2Rfid"].ToString() }; } ct.BeginTime = beginTime; ct.EndTime = endTime; } //学生数据 sql = @"select s.student_no,s.student_name,s.student_rfid from course_task_student cts left join student s where s.student_id=cts.student_id and cts.course_task_id=?"; ds = SqlLiteHelper.ExecuteQuery(sql, id); foreach (DataRow row in ds.Tables[0].Rows) { ct.AddStudent(new CardInfo { No = row["student_no"].ToString(), Name = row["student_name"].ToString(), Rfid = row["student_rfid"].ToString() }); } //作品数据 sql = @"select student_no,file_path from course_task_file where course_task_id=?"; ds = SqlLiteHelper.ExecuteQuery(sql, id); foreach (DataRow row in ds.Tables[0].Rows) { ct.AddWork(new WorkInfo { StudentNo = row["student_no"].ToString(), FilePath = row["file_path"].ToString() }); } return(ct); }
public async Task <Guid> Save([FromBody] CourseTask task) => await taskService.Save(task).ConfigureAwait(false);
private void btnSyncCourseTask_Click(object sender, EventArgs e) { /*JsonResult jr = RemoteServiceProxy.UploadWork(@"C:\Users\乙郎\Pictures\7cbc9488-0a4b-4ab5-a6ed-70e319096680.png", "12", "14"); * AddLog("result=" + jr.message);*/ EnableButton(false); List <long> courseTaskIds = StoreModel.GetFinishCourseTaskIds(); pb.Maximum = courseTaskIds.Count; int syncCount = 0; int successCount = 0; int errorCount = 0; foreach (var id in courseTaskIds) { syncCount++; pb.Value = syncCount; CourseTask ct = StoreModel.GetById(id); JsonResultList list = RemoteServiceProxy.Report(ct, FrmActive.machineCode, FrmActive.activeCode); if (list.error) { AddLog("同步课程任务失败:" + id.ToString() + " 错误信息:" + list.message); errorCount++; continue; } List <WorkInfo4Upload> works = RemoteServiceProxy.PrepareWork(ct.Works, list.data); //然后传到服务器!--作品! bool error = false; foreach (var w in works) { JsonResult jr = RemoteServiceProxy.ReportWork(w); if (jr.error) { AddLog("同步作品失败:" + id.ToString() + " 作品=" + w.StudentNo); error = true; continue; } } if (!error) { StoreModel.FinishReportCourseTask(id); StoreModel.RemoveFiles(ct.Works); successCount++; } else { errorCount++; } } //全部更新完成了 //界面刷新一下 this.UpdateLeftCourseCount(); pb.Value = 0; EnableButton(true); AddLog("同步数量:" + syncCount.ToString() + " 成功数量:" + successCount.ToString() + " 错误数量:" + errorCount.ToString()); }
public async Task <Guid> AddTask([FromQuery] Guid courseId, [FromBody][Required] CourseTask task) => await courseService.AddTask(courseId, task).ConfigureAwait(false);