public async Task <IActionResult> AddStudentSolution(StudentHomework studentHomework) { if (ModelState.IsValid) { var student = GetLoggedStudent().Result; var homeworkByStudent = await _context.StudentHomework .FirstOrDefaultAsync(x => x.StudentId == student.Id && x.HomeworkId == studentHomework.HomeworkId); homeworkByStudent.IsDone = true; homeworkByStudent.StudentSubmissionDate = DateTime.Now; homeworkByStudent.SolutionTextContent = studentHomework.SolutionTextContent; string imageName = null; if (studentHomework.PhotoSolution != null) { string uploadsDir = Path.Combine(_webHostEnvironment.WebRootPath, "media/studentHomeworkSolutions"); imageName = Guid.NewGuid().ToString() + "_" + studentHomework.PhotoSolution.FileName; // this gives unique id so no same image twice uploaded string filePath = Path.Combine(uploadsDir, imageName); FileStream fileStream = new FileStream(filePath, FileMode.Create); await studentHomework.PhotoSolution.CopyToAsync(fileStream); fileStream.Close(); } homeworkByStudent.ImageSolution = imageName; homeworkByStudent.PhotoSolution = studentHomework.PhotoSolution; _context.StudentHomework.Update(homeworkByStudent); await _context.SaveChangesAsync(); return(Json(new { text = "You submitted your assignment!" })); } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { text = "Server error!" })); }
//View Homework private async void bunifuThinButton2_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count == 1) { var item = listView1.SelectedItems[0]; //Sets viewItem to 0, refrains application from crashing StudentHomework hw = (StudentHomework)item.Tag; if (hw == null) //Null is when the entity of the students homework is empty { MessageBox.Show("Student has not yet submitted homework", "Not Submitted", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SaveFileDialog sfd = new SaveFileDialog(); //Constructor, saveFileDialog if (sfd.ShowDialog() == DialogResult.OK) { using (var client = new WebClient()) //Constructor to create a new WebClient. { await client.DownloadFileTaskAsync(new Uri(hw.Url), sfd.FileName); //Downloads Homework according to when a student has subbmitted it. } } } else if (listView1.SelectedItems.Count == 0) //Ensures teacher atleast selects an item { MessageBox.Show("Please select an item from the list!", "No item selected", MessageBoxButtons.OK, MessageBoxIcon.Information); } else //Ensures a teacher doesnt select multipe items { MessageBox.Show("Please select only one item!", "Multiple items selected", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void Rejected(int ShomeworkId, string comments, int studentId) { var studentHomework = new StudentHomework(); StudentHomeworkRepository repository = new StudentHomeworkRepository(); repository.Rejected(ShomeworkId, comments); EmailNotification notification = new EmailNotification(new EmailSender()); StudentService service = new StudentService(); Student student = service.GetStudentByID(studentId); notification.NotifystudentWhenHomeworkIsRejected(student.Email, student.FirstName, ShomeworkId); }
public void AddGrade(int ShomeworkId, int grade, int studentId) { var studentHomework = new StudentHomework(); StudentHomeworkRepository repository = new StudentHomeworkRepository(); repository.AddGrade(ShomeworkId, grade); EmailNotification notification = new EmailNotification(new EmailSender()); StudentService service = new StudentService(); Student student = service.GetStudentByID(studentId); notification.NotifystudentWhenHomeworkIsAccepted(student.Email, student.FirstName, ShomeworkId); }
//get homeworks by student id public static List <StudentHomework> GetStudentHomeWorks(int id) { List <StudentHomework> homeworks = new List <StudentHomework>(); string cs = ConfigurationManager.ConnectionStrings["TeamB"].ConnectionString; using (SqlConnection connection = new SqlConnection(cs)) { connection.Open(); SqlCommand command = new SqlCommand(); command.CommandText = "spGetStudentHomeworks"; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@ID", id); command.Connection = connection; using (var reader = command.ExecuteReader()) { while (reader.Read()) { var studenthomework = new StudentHomework { SHomeID = Convert.ToInt32(reader["SHomeID"]), HomeworkID = Convert.ToInt32(reader["HomeworkID"]), StatusID = reader["StatusID"].ToString(), UploadedFiles = reader["UploadedFiles"].ToString(), Grade = Convert.ToInt32(reader["Grade"]), StartDate = Convert.ToDateTime(reader["StartDate"]), EndDate = Convert.ToDateTime(reader["EndDate"]), Requirements = reader["Requirements"].ToString(), Comments = reader["Comments"].ToString() }; if (studenthomework != null) { homeworks.Add(studenthomework); } } // return homeworks; } } return(homeworks); }
//öğrenci ödevini yüklüyor. public async Task <string> HomeworkUploadToHomework(List <IFormFile> files, int homeworkId, int userId, string path) { foreach (var formFile in files) { if (formFile.Length > 0) { var filename = formFile.FileName; var guidKey = Guid.NewGuid(); if (!Directory.Exists(path + "\\Upload\\Homeworks\\")) { Directory.CreateDirectory(path + "\\Upload\\Homeworks\\"); } var extension = formFile.FileName.Split(".")[1]; var fullPath = path + "\\Upload\\Homeworks\\" + guidKey + "." + extension; using (var stream = System.IO.File.Create(fullPath)) { await formFile.CopyToAsync(stream); } var studentHomework = new StudentHomework() { LessonHomeworkId = homeworkId, UserId = userId, FileKey = guidKey, FileName = filename, FilePath = fullPath }; ctx.StudentHomeworks.Add(studentHomework); } } await ctx.SaveChangesAsync(); return("Upload Successyfully"); }
public void Update(StudentHomework updated) { var shw = JsonConvert.SerializeObject(updated); UpdateStudentHomeworkRequest(shw); }
public void Insert(StudentHomework inserted) { var shw = JsonConvert.SerializeObject(inserted); InsertStudentHomeworkRequest(shw); }
public void Delete(StudentHomework deleted) { throw new NotImplementedException(); }
public void UpdateStudentHomework(int ShomeworkId, int grade, string status, string path) { var studentHomework = new StudentHomework(); studentHomework = StudentHomeworkRepository.UpdateStudentHomeworkBySHomeworkID(ShomeworkId, grade, status, path); }
public static StudentHomework ToEntity(this StudentHomeworkModel model, StudentHomework destination) { return(model.MapTo(destination)); }
public static StudentHomeworkModel ToModel(this StudentHomework entity) { return(entity.MapTo <StudentHomework, StudentHomeworkModel>()); }