public async Task <ActionResult> TaskFiles(int CourseTopicFileId) { CourseTopicFile courseTopicFile = await db.GetCourseTopicFileByIdAsync(CourseTopicFileId); if (courseTopicFile == null) { return(RedirectToAction("Error")); } bool IsTeacher = await db.IsTeacherByEmailAsync(User.Identity.Name); if (!IsTeacher) { return(RedirectToAction("Error")); } bool IsAccess = await db.HaveTeacherAccessToCourseByEmailAsync(User.Identity.Name, courseTopicFile.CourseId); if (!IsAccess) { return(RedirectToAction("Error")); } List <CourseTopicFileTask> CourseTopicFileTasks = await db.GetCourseTopicFileTasksByCourseTopicFileId(CourseTopicFileId); ViewBag.UserCourseColor = (await db.GetUserCourseAsync(User.Identity.Name, courseTopicFile.CourseId)).ColorHue; return(View(CourseTopicFileTasks.Select(x => new CourseTopicFileTaskVM(x)).ToList())); }
public async Task <ActionResult> LabZoom(int CourseTopicFileId) { CourseTopicFile courseTopicFile = await db.GetCourseTopicFileByIdAsync(CourseTopicFileId); File file = await db.GetFileByCourseTopicFileIdAsync(User.Identity.Name, CourseTopicFileId); if (courseTopicFile == null || !file.FileType.Name.ToLower().Contains("zoom") || !await db.HaveUserAccessToCourseTopicFile(User.Identity.Name, CourseTopicFileId)) { return(RedirectToAction("error", "pages")); } bool IsTeacher = await db.IsTeacherByEmailAsync(User.Identity.Name); bool IsHaveAccess = false; if (IsTeacher) { IsHaveAccess = await db.HaveTeacherAccessToCourseByEmailAsync(User.Identity.Name, courseTopicFile.CourseId); Session["FileTypes"] = Session["FileTypes"] == null?db.GetFileTypesLab() : Session["FileTypes"]; } else { IsHaveAccess = await db.HaveUserAccessToCourseAsync(User.Identity.Name, courseTopicFile.CourseId); } if (!IsHaveAccess) { return(RedirectToAction("index", "pages")); } FilesLocation location = db.GetFileLocationByFileId(file.FileId); bool IsImageCompressed = !String.IsNullOrWhiteSpace(location.AttachedFileLocation); String attachedFile = IsImageCompressed ? location.AttachedFileLocation : location.FileLocation; String[] FileName = attachedFile.Split('\\'); if (IsImageCompressed) { int OriginalImageWidth = Image.FromStream(new FileStream(location.FileLocation, FileMode.Open, FileAccess.Read)).Width; int CompressedImageWidth = Image.FromStream(new FileStream(location.AttachedFileLocation, FileMode.Open, FileAccess.Read)).Width; int CompressionRatio = (int)Math.Ceiling(double.Parse(((double)OriginalImageWidth / CompressedImageWidth).ToString())); Session["ImageCompressSize_" + User.Identity.Name + file.FileId] = CompressionRatio; } else { Session["ImageCompressSize_" + User.Identity.Name + file.FileId] = 1; } ViewData["FileName"] = FileName[FileName.Length - 1]; ViewData["CourseTopicFile"] = courseTopicFile; ViewData["file"] = file; ViewBag.ShowNavigation = false; ViewBag.HideSiteLogo = true; return(View(file)); }
public async Task <ActionResult> Statistics(int CourseTopicFileId, String search) { CourseTopicFile courseTopicFile = await db.GetCourseTopicFileByIdAsync(CourseTopicFileId); if (courseTopicFile == null) { return(RedirectToAction("Error")); } bool IsTeacher = await db.IsTeacherByEmailAsync(User.Identity.Name); if (!IsTeacher) { return(RedirectToAction("Error")); } bool IsAccess = await db.HaveTeacherAccessToCourseByEmailAsync(User.Identity.Name, courseTopicFile.CourseId); if (!IsAccess) { return(RedirectToAction("Error")); } if ((await db.GetStatisticsByCourseTopicFileId(CourseTopicFileId)).Count == 0) { return(RedirectToAction("Error")); } ViewBag.UserCourseColor = (await db.GetUserCourseAsync(User.Identity.Name, courseTopicFile.CourseId)).ColorHue; ViewBag.Course = await db.GetCourseByCourseTopicFileIdAsync(CourseTopicFileId); ViewBag.CourseTopic = await db.GetCourseTopicByCourseTopicFileIdAsync(CourseTopicFileId); ViewBag.CourseTopicFileId = CourseTopicFileId; if (!String.IsNullOrWhiteSpace(search)) { List <StatisticVM> statistics = (await db.SearchStatisticsAsync(CourseTopicFileId, search)).Select(x => new StatisticVM(x)).ToList(); ViewBag.Search = search; return(View(statistics)); } return(View((await db.GetStatisticsByCourseTopicFileId(CourseTopicFileId)).Select(x => new StatisticVM(x)).ToList())); }
public async Task <ActionResult> LabTools(int CourseTopicFileId) { CourseTopicFile courseTopicFile = await db.GetCourseTopicFileByIdAsync(CourseTopicFileId); File file = await db.GetFileByCourseTopicFileIdAsync(User.Identity.Name, CourseTopicFileId); if (courseTopicFile == null || !file.FileType.Name.ToLower().Contains("tools") || !await db.HaveUserAccessToCourseTopicFile(User.Identity.Name, CourseTopicFileId)) { return(RedirectToAction("error", "pages")); } bool IsTeacher = await db.IsTeacherByEmailAsync(User.Identity.Name); bool IsHaveAccess = false; if (IsTeacher) { IsHaveAccess = await db.HaveTeacherAccessToCourseByEmailAsync(User.Identity.Name, courseTopicFile.CourseId); Session["FileTypes"] = Session["FileTypes"] == null?db.GetFileTypesLab() : Session["FileTypes"]; } else { IsHaveAccess = await db.HaveUserAccessToCourseAsync(User.Identity.Name, courseTopicFile.CourseId); } if (!IsHaveAccess) { return(RedirectToAction("Course", "pages", new { id = courseTopicFile.CourseId })); } FilesLocation location = db.GetFileLocationByFileId(file.FileId); string[] FileName = location.FileLocation.Split('\\'); ViewData["CourseTopicFile"] = courseTopicFile; ViewData["FileName"] = FileName[FileName.Length - 1]; ViewBag.ShowNavigation = false; ViewBag.HideSiteLogo = true; try { excel = new Application(); books = excel.Workbooks; book = books.Open(location.AttachedFileLocation); sheet = book.Sheets[1]; xlRange = sheet.UsedRange; int x = GetColumn(); int y = GetRow(); List <LabPixelModel> labPixels = new List <LabPixelModel>(); String[,] sh = new String[y - 1, x]; for (int i = 2; i <= y; i++) { labPixels.Add(new LabPixelModel() { x1 = (int)xlRange.Cells[i, 1].Value2, y1 = (int)xlRange.Cells[i, 2].Value2, x2 = (int)xlRange.Cells[i, 3].Value2, y2 = (int)xlRange.Cells[i, 4].Value2, L = (double)xlRange.Cells[i, 5].Value2, A = (double)xlRange.Cells[i, 6].Value2, B = (double)xlRange.Cells[i, 7].Value2, V = (double)xlRange.Cells[i, 8].Value2, C = (double)xlRange.Cells[i, 9].Value2, M = (double)xlRange.Cells[i, 10].Value2, Y = (double)xlRange.Cells[i, 11].Value2, Comment = xlRange.Cells[i, 12].Value2.ToString() //Color = xlRange.Cells[i, 13].Value2.ToString() }); } Session["PixelsInfo_" + User.Identity.Name + $"_file{file.FileId}"] = labPixels; } catch { Session["PixelsInfo_" + User.Identity.Name + $"_file{file.FileId}"] = null; } //Excel close books.Close(); excel.Application.Quit(); excel.Quit(); int hWnd = excel.Application.Hwnd; GetWindowThreadProcessId((IntPtr)hWnd, out uint processID); Process.GetProcessById((int)processID).Kill(); book = null; excel = null; sheet = null; return(View(file)); }