public IActionResult OnGet(int?id) { int userId = 0; if (HttpContext.Session.GetInt32(SD.UserSessionId) != null) { if (HttpContext.Session.GetInt32(SD.UserSessionId).HasValue) { userId = HttpContext.Session.GetInt32(SD.UserSessionId).Value; } } UserObj = _unitOfWork.User.GetFirstorDefault(u => u.ID == userId); if (id == null) { return(NotFound()); } SubmissionObj = _unitOfWork.Submission.GetFirstorDefault(m => m.ID == id); if (SubmissionObj == null) { return(NotFound()); } AssignmentObj = _unitOfWork.Assignment.GetFirstorDefault(m => m.ID == SubmissionObj.AssignmentId); return(Page()); }
//Submission methods public void AddSubmission(Models.Submission submission, int studentAssignmentId) { submission = new Models.Submission(); submission.StudentAssignmentId = studentAssignmentId; _context.Submission.Add(submission); _context.SaveChanges(); }
public async Task <IActionResult> OnPostAsync([FromForm] string source) { Task = await db.Tasks.FindAsync(TaskId); if (Task == null) { return(NotFound()); } var authorId = (uint)HttpContext.Session.GetInt32("username"); var filename = $"{Task.Id}_{authorId}_{Language.ToString()}"; var path = Path.Combine(env.ContentRootPath, "storage", "sources", filename); var i = 1; while (System.IO.File.Exists($"{path}_{i}{LanguageExtension}")) { i++; } filename += $"_{i}{LanguageExtension}"; path += $"_{i}{LanguageExtension}"; var submission = new Models.Submission { Task = Task, AuthorId = authorId, Sequence = (uint)i, Working = true, Error = "", Language = Language, Filename = filename, }; using (var fs = new FileStream(path, FileMode.CreateNew, FileAccess.Write)) using (var sw = new StreamWriter(fs, new UTF8Encoding(false))) { await sw.WriteAsync(source); } submission.Size = (uint)new FileInfo(path).Length; db.Submissions.Add(submission); await db.SaveChangesAsync(); queue.QueueBackgroundWorkItem(submission); return(RedirectToPage("/Submissions/Index", new { taskId = TaskId, })); }
public async Task <Guid> NewSubmission(IEnumerable <Stop> stops, UserProfile userProfile) { InitializeBlobContainer(); Guid submissionId = Guid.NewGuid(); Models.Submission submission = new Models.Submission { DateSubmitted = DateTime.UtcNow, Id = submissionId, RecordCount = stops.Count(), OfficerId = userProfile.OfficerId, OfficerName = userProfile.Name, MinStopDate = DateTime.Parse(stops.OrderBy(x => x.Date).First().Date), MaxStopDate = DateTime.Parse(stops.OrderByDescending(x => x.Date).First().Date), }; await _submissionCosmosDbService.AddSubmissionAsync(submission); return(submissionId); }
public IActionResult OnPost() { int userId = 0; if (HttpContext.Session.GetInt32(SD.UserSessionId) != null) { if (HttpContext.Session.GetInt32(SD.UserSessionId).HasValue) { userId = HttpContext.Session.GetInt32(SD.UserSessionId).Value; } } UserObj = _unitOfWork.User.GetFirstorDefault(u => u.ID == userId); if (UserObj.UserType == 'I') { Models.Notification NotificationObj = new Models.Notification(); var points = SubmissionObj.Points; SubmissionObj = _context.Submission.Where(x => x.ID == SubmissionObj.ID).FirstOrDefault(); AssignmentObj = _context.Assignment.Where(x => x.ID == SubmissionObj.AssignmentId).FirstOrDefault(); AssignmentObj.Grade = points; NotificationObj.sourceID = SubmissionObj.AssignmentId; NotificationObj.Type = 'A'; NotificationObj.Message = "Assignment: " + AssignmentObj.Title + " Has been Graded"; _context.Notification.Add(NotificationObj); _context.SaveChanges(); var objFromDb = _unitOfWork.Submission.Get(SubmissionObj.ID); objFromDb.Points = SubmissionObj.Points; _unitOfWork.Submission.Update(objFromDb); _unitOfWork.Save(); return(Redirect("/Assignments/Grade?id=" + objFromDb.AssignmentId.ToString())); } return(NotFound()); }
private Stream GetSourceStream(Models.Submission submission) { var path = Path.Combine(env.ContentRootPath, "storage", "sources", submission.Filename); return(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)); }
public async Task UpdateSubmissionAsync(string id, Models.Submission submission) { await _container.UpsertItemAsync <Models.Submission>(submission, new PartitionKey(id)); }
public async Task AddSubmissionAsync(Models.Submission submission) { await _container.CreateItemAsync <Models.Submission>(submission, new PartitionKey(submission.Id.ToString())); }
async public void UpdateSubmission(Models.Submission submission) { _context.Attach(submission).State = EntityState.Modified; await _context.SaveChangesAsync(); }
public void RemoveSubmission(int studentAssignmentId) { Models.Submission submission = _context.Submission.FirstOrDefault(s => s.StudentAssignmentId == studentAssignmentId); _context.Submission.Remove(submission); _context.SaveChanges(); }
public async Task <IActionResult> OnPostAsync() { if (Sf.ReportFile == null || Sf.ReportFile.Length == 0) { ErrorMessage = "No file selected"; return(RedirectToPage("/Student/Submission/Index")); } if (Sf.ReportFile.Length >= 52428800) { ErrorMessage = "The file should not exceed 50MB."; return(RedirectToPage("/Student/Submission/Index")); } var submissionType = await _context.SubmissionType .FirstOrDefaultAsync(s => s.SubmissionTypeId == SubmissionType.SubmissionTypeId); if (submissionType.GraceDate < DateTime.Now || submissionType.StartDate > DateTime.Now) { ErrorMessage = "Report submission denied."; return(RedirectToPage("/Student/Submission/Index")); } var username = HttpContext.Session.GetString("_username"); var rootPath = _appEnvironment.ContentRootPath; var folderPath = $"\\Files\\{username}\\"; var filePathWithoutName = rootPath + folderPath; Directory.CreateDirectory(filePathWithoutName); var fileName = Sf.ReportFile.FileName; var filePath = filePathWithoutName + fileName; using (var fstream = new FileStream(filePath, FileMode.Create)) { await Sf.ReportFile.CopyToAsync(fstream); } var student = await _context.Student .Where(s => s.DateDeleted == null) .FirstOrDefaultAsync(s => s.AssignedId == username); var project = await _context.Project .Where(p => p.DateDeleted == null) .FirstOrDefaultAsync(p => p.ProjectId == student.ProjectId); var status = ""; if (submissionType.StartDate <= DateTime.Now && submissionType.EndDate >= DateTime.Now) { status = "New"; } if (submissionType.EndDate <= DateTime.Now && submissionType.GraceDate >= DateTime.Now) { status = "Late"; } var submission = new Models.Submission() { SubmissionName = Sf.Type, SubmissionStatus = status, SubmissionFolder = folderPath, SubmissionFile = fileName, SubmissionSize = Sf.ReportFile.Length, UploadDate = DateTime.Now, ProjectId = project.ProjectId, SubmissionTypeId = SubmissionType.SubmissionTypeId, DateCreated = DateTime.Now }; _context.Submission.Add(submission); await _context.SaveChangesAsync(); var supervisor = await _context.Supervisor .Where(s => s.DateDeleted == null) .FirstOrDefaultAsync(s => s.AssignedId == project.SupervisorId); var mailsubject = $"FYP System - Submission for {Sf.Type}"; var mailbody = $@"Dear {supervisor.SupervisorName}, The {Sf.Type} had been submitted for the project below: Project ID: {project.AssignedId} Project Title: {project.ProjectTitle} Submission Details Batch: {Sf.Batch} Submission Type: {submission.SubmissionName} Submission File Name: {submission.SubmissionFile} Submmisionn Upload Date: {submission.UploadDate} Please navigate to the system menu under My Supervision --> Supervision List to check for more information. Please contact the Coordinator if you found any problem or difficulty using the system. Thank You. Yours Sincerely, {student.StudentName} {student.AssignedId} (FYP Student)"; await _emailSender.SendEmailAsync(student.StudentEmail, supervisor.SupervisorEmail, mailsubject, mailbody); var cosupervisor = await _context.Supervisor .Where(s => s.DateDeleted == null) .FirstOrDefaultAsync(s => s.AssignedId == project.CoSupervisorId); if (cosupervisor != null) { var mailsubject2 = $"FYP System - Submission for {Sf.Type}"; var mailbody2 = $@"Dear {cosupervisor.SupervisorName}, The {Sf.Type} had been submitted for the project below: Project ID: {project.AssignedId} Project Title: {project.ProjectTitle} Submission Details Batch: {Sf.Batch} Submission Type: {submission.SubmissionName} Submission File Name: {submission.SubmissionFile} Submmisionn Upload Date: {submission.UploadDate} Please navigate to the system menu under My Supervision --> Supervision List to check for more information. Please contact the Coordinator if you found any problem or difficulty using the system. Thank You. Yours Sincerely, {student.StudentName} {student.AssignedId} (FYP Student)"; await _emailSender.SendEmailAsync(student.StudentEmail, cosupervisor.SupervisorEmail, mailsubject2, mailbody2); } SuccessMessage = $"{submission.SubmissionName} for project submitted successfully."; return(RedirectToPage("/Student/Submission/Index")); }