public ActionResult SelectLogImage(IEnumerable <int> ImageIDs) { LogBusiness LogBO = new LogBusiness(); //Lay nhung image da chon tu db, sort theo rollcall ID List <LogImage> ImageList = ImageIDs.Select(id => LogBO.GetLogImageByID(id)) .OrderBy(img => img.AttendanceLog.RollCallID).ToList(); List <int> RollCallIDs = ImageList.Select(img => img.AttendanceLog.RollCallID).Distinct().ToList(); List <RecognizerResult> Result = new List <RecognizerResult>(); foreach (int RollCallID in RollCallIDs) { List <LogImage> RollCallImages = ImageList.Where(img => img.AttendanceLog.RollCallID == RollCallID).ToList(); List <String> ImagePaths = RollCallImages.Select(img => Server.MapPath("~/Content/Log/" + img.ImageLink)).ToList(); //Nhan dien khuon mat, dua vao list de show ra Result.AddRange(FaceBusiness.RecognizeStudentForAttendance(RollCallID, ImagePaths)); } //Danh sash student de tao select list ViewBag.Students = StuBO.GetAllStudents(); return(View("LogImagesResult", Result)); }
public ActionResult CheckAttendanceAuto(int RollCallID, IEnumerable <HttpPostedFileBase> ImageFiles) { RollCall rollCall = RollBO.GetRollCallByID(RollCallID); List <String> ImagePaths = new List <string>(); foreach (HttpPostedFileBase file in ImageFiles) { //Save file anh xuong String OldPath = Server.MapPath("~/Content/Temp/" + file.FileName); file.SaveAs(OldPath); //Resize file anh, luu vao thu muc log, ten mon hoc, ten lop String NewPath = Server.MapPath("~/Content/Log/" + rollCall.Class.ClassName + "_" + rollCall.Subject.ShortName + "_" + file.FileName); FaceBusiness.ResizeImage(OldPath, NewPath); ImagePaths.Add(NewPath); } //Nhan dien tung khuon mat trong anh List <RecognizerResult> Result = FaceBusiness.RecognizeStudentForAttendance(RollCallID, ImagePaths); //Dua reseult nay cho AttendanceBO xu ly AttendanceBusiness AttenBO = new AttendanceBusiness(); AttendanceLog Log = AttenBO.WriteAttendanceAutoLog(RollCallID, Result); //Danh sach sinh vien trong log StudentBusiness StuBO = new StudentBusiness(); List <Student> Students = StuBO.Find(stu => stu.StudentAttendances. Any(attend => attend.LogID == Log.LogID && attend.IsPresent)).ToList(); RollCall CurrentRollCall = RollBO.GetRollCallByID(RollCallID); //Tao model de show trong view AttendanceViewModel model = new AttendanceViewModel(); model.CurrentRollCall = CurrentRollCall; model.PresentStudents = Students; model.RecognizeResult = Result; return(View(model)); }
public ActionResult RecognizeTesting(int RollCallID, IEnumerable <HttpPostedFileBase> ImageFiles) { List <String> ImagePaths = new List <string>(); foreach (HttpPostedFileBase file in ImageFiles) { //Save file anh xuong String OldPath = Server.MapPath("~/Content/Temp/" + file.FileName); file.SaveAs(OldPath); //Resize file anh, luu vao thu muc log, ten mon hoc, ten lop String NewPath = Server.MapPath("~/Content/Temp/Resized/" + file.FileName); FaceBusiness.ResizeImage(OldPath, NewPath); ImagePaths.Add(NewPath); } //Nhan dien tung khuon mat trong anh List <RecognizerResult> Result = FaceBusiness.RecognizeStudentForAttendance(RollCallID, ImagePaths); return(View("RecognizeTestingResult", Result)); }
public ActionResult CheckAttendanceAuto(int RollCallID, List <HttpPostedFileBase> ImageFiles, DateTime?AttendanceDate) { RollCallBusiness RollBO = new RollCallBusiness(); var rollCall = RollBO.GetRollCallByID(RollCallID); List <String> ImagePaths = new List <string>(); foreach (HttpPostedFileBase file in ImageFiles) { //Save file anh xuong String OldPath = Server.MapPath("~/Content/Temp/" + file.FileName); file.SaveAs(OldPath); //Resize file anh, luu vao thu muc log, nho them ngay thang truoc String NewPath = Server.MapPath("~/Content/Log/" + rollCall.Class.ClassName + "_" + rollCall.Subject.ShortName + "_" + file.FileName); FaceBusiness.ResizeImage(OldPath, NewPath); ImagePaths.Add(NewPath); //Nhan dien tung khuon mat trong anh } List <RecognizerResult> Results = FaceBusiness.RecognizeStudentForAttendance(RollCallID, ImagePaths); //Dua result nay cho AttendanceBO xu ly AttendanceBusiness AttenBO = new AttendanceBusiness(); AttendanceLog Log = null; if (AttendanceDate == null) { Log = AttenBO.WriteAttendanceAutoLog(RollCallID, Results); } else { Log = AttenBO.WriteAttendanceAutoLog(RollCallID, Results, AttendanceDate.Value); } //Danh sach sinh vien trong log List <int> StudentIDs = AttenBO.GetStudentIDList(Results); //Lay danh sach sinh vien ton tai trong log StudentBusiness StuBO = new StudentBusiness(); //List<Student> Students = StuBO.Find(stu => StudentIDs.Contains(stu.StudentID)).ToList(); /* * var StudentsJson = Students.ToList().Select(s => new * { * studentID = s.StudentID, * studentCode = s.StudentCode, * studentName = s.FullName * }); */ var StudentsJson = Log.StudentAttendances.Select(sa => new { studentID = sa.StudentID, studentCode = sa.Student.StudentCode, studentName = sa.Student.FullName, isPresent = sa.IsPresent }); return(Json(StudentsJson, JsonRequestBehavior.AllowGet)); }