public ActionResult TakeAttendance(HttpPostedFileBase zip, HttpPostedFileBase img, FormCollection collector) { #region Declaring Varibles string path = Server.MapPath("~/Uploads/TrainingSet/"); string haarcascades = HttpContext.Server.MapPath("~/haarcascades/haarcascade_frontalface_default.xml"); string theePath = ""; BusinessLogicHandler _gateWay; Lecture _mod; List<string> User_Id; #endregion #region getting the modulecode _gateWay = new BusinessLogicHandler(); _mod = new Lecture(); _mod = _gateWay.GetLecture(Convert.ToInt32(collector.GetValue("Lecture").AttemptedValue)); #endregion #region Checking or Creating the directory string newPath = Server.MapPath("~/Uploads/Attendance/"); if (Directory.Exists(newPath)) { if (Directory.Exists(newPath + _mod.ModuleCode)) { theePath = newPath + _mod.ModuleCode.Trim() + "/" + _mod.VenueCode.Trim() + "/" + DateTime.Today.ToString("ddMMMMyyyy"); if (!Directory.Exists(theePath)) Directory.CreateDirectory(theePath); } else { Directory.CreateDirectory(newPath + _mod.ModuleCode); theePath = newPath + _mod.ModuleCode.Trim() + "/" + _mod.VenueCode.Trim() + "/" + DateTime.Today.ToString("ddMMMMyyyy"); if (!Directory.Exists(theePath)) Directory.CreateDirectory(theePath); } } else { Directory.CreateDirectory(newPath); } string imgPath = "~/Uploads/Attendance/" + _mod.ModuleCode.Trim() + "/" + _mod.VenueCode.Trim() + "/" + DateTime.Today.ToString("ddMMMMyyyy"); #endregion #region Image not null if (img != null && zip == null) { User_Id = new List<string>(); Bitmap _Img = new Bitmap(img.InputStream); #region processing the img CoreSysFunction _coreFunction = new CoreSysFunction(); User_Id.AddRange(_coreFunction.DetectAndRecognize(_Img, path, haarcascades)); Bitmap toSave = _coreFunction.IdentifyAndMark(haarcascades, _Img); toSave.Save(theePath +"/"+ _mod.VenueCode.Trim()+".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); imgPath += "/" + _mod.VenueCode.Trim() + ".jpg"; #endregion #region object to view page Bridge _bridge = new Bridge(); _bridge.filePath = new List<string>(); _bridge.filePath.Add( imgPath); _bridge.User_Id = new List<string>(); _bridge.User_Id = User_Id; _bridge.dateSlice = collector.GetValue("dateHoldhidden").AttemptedValue.Split(' '); _bridge.Lecture_Id = Convert.ToInt32(collector.GetValue("Lecture").AttemptedValue); Session["Data"] = _bridge; #endregion return RedirectToActionPermanent("ViewAttendees"); } #endregion #region Image not null and zip not null else if (zip != null && img != null) { User_Id = new List<string>(); Bridge _bridge = new Bridge(); List<string> fileNames = new List<string>(); _bridge.filePath = new List<string>(); Bitmap _Img = new Bitmap(img.InputStream); #region processing the img CoreSysFunction _coreFunction = new CoreSysFunction(); User_Id.AddRange(_coreFunction.DetectAndRecognize(_Img, path, haarcascades)); Bitmap toSave = _coreFunction.IdentifyAndMark(haarcascades, _Img); toSave.Save(theePath + "/" + _mod.VenueCode.Trim() + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); _bridge.filePath.Add(imgPath +"/" + _mod.VenueCode.Trim() + ".jpg"); #endregion #region Processing zip Stream zipStream = zip.InputStream; using (var _img = ZipFile.Read(zipStream)) { foreach (var file in _img.Entries) { file.Extract(theePath, ExtractExistingFileAction.OverwriteSilently); Image bmp = Image.FromFile(theePath + "/" + file.FileName); Bitmap mbmp = new Bitmap(bmp); fileNames.Add(theePath + "/" + file.FileName); User_Id.AddRange(_coreFunction.DetectAndRecognize(mbmp, path, haarcascades)); toSave = _coreFunction.IdentifyAndMark(haarcascades, mbmp); try { toSave.Save(imgPath + "/" + file.FileName); _bridge.filePath.Add(imgPath += "/" + file.FileName); } catch (Exception e) { } } } #endregion #region object to view _bridge.User_Id = new List<string>(); _bridge.User_Id = User_Id.Distinct(); _bridge.dateSlice = collector.GetValue("dateHoldhidden").AttemptedValue.Split(' '); _bridge.Lecture_Id = Convert.ToInt32(collector.GetValue("Lecture").AttemptedValue); Session["Data"] = _bridge; #endregion return RedirectToActionPermanent("ViewAttendees"); } #endregion #region Zip not null else if (zip != null) { return RedirectToActionPermanent("ViewAttendees"); } #endregion else { return RedirectToActionPermanent("Index"); } }
public ActionResult Schedule(HttpPostedFileBase zip, HttpPostedFileBase img, FormCollection collector) { #region Declaring Varibles string path = Server.MapPath("~/Uploads/"); string haarcascades = HttpContext.Server.MapPath("~/haarcascades/haarcascade_frontalface_default.xml"); string theePath = ""; List<string> User_Id; string[] dateSlice = collector.GetValue("dateHoldhidden").AttemptedValue.Split(' '); string[] timeSlice = collector.GetValue("timeHoldhidden").AttemptedValue.Split(' '); string rawDate = dateSlice[3] + "-" + dateSlice[1] + "-" + dateSlice[2] + " " + timeSlice[0] + " " + timeSlice[1]; DateTime date = new DateTime(); date = DateTime.Parse(rawDate); DateTimeOffset ofset = new DateTimeOffset(date, new TimeSpan(+1, 0, 0)); //date = DateTime.ParseExact(rawDate, "yyyy-MMM-dd HH:mm tt", null); #endregion #region Checking or Creating the directory string newPath = Server.MapPath("~/Uploads/Attendance/"); if (Directory.Exists(newPath)) { theePath = newPath + collector.GetValue("Lecture").AttemptedValue + DateTime.Today.ToString("ddMMMMyyyy"); if (!Directory.Exists(theePath)) Directory.CreateDirectory(theePath); } else { Directory.CreateDirectory(newPath); } #endregion if (img != null && zip == null) { User_Id = new List<string>(); Bitmap _Img = new Bitmap(img.InputStream); //if _Img.GetPropertyItem() #region processing the img CoreSysFunction _coreFunction = new CoreSysFunction(); //var c = BackgroundJob.Schedule(() => User_Id.AddRange(_coreFunction.DetectAndRecognize(_Img, path, haarcascades)), ofset); c = BackgroundJob.Schedule(() => RunAutoDetection(), DateTime.Now); RecurringJob.AddOrUpdate(c.ToString(), () => RunAutoDetection(), Cron.Weekly(DayOfWeek.Monday, 5, 30)); #endregion #region object to view page //Bridge _bridge = new Bridge(); //_bridge.User_Id = new List<string>(); //_bridge.User_Id = User_Id; //_bridge.dateSlice = collector.GetValue("dateHoldhidden").AttemptedValue.Split(' '); //_bridge.Lecture_Id = Convert.ToInt32(collector.GetValue("Lecture").AttemptedValue); //Session["Data"] = _bridge; #endregion //return RedirectToActionPermanent("Index", "Home"); return Json(""); } else if (zip != null && img != null) { User_Id = new List<string>(); Bitmap _Img = new Bitmap(img.InputStream); #region processing the img CoreSysFunction _coreFunction = new CoreSysFunction(); User_Id.AddRange(_coreFunction.DetectAndRecognize(_Img, path, haarcascades)); #endregion #region Processing zip Stream zipStream = zip.InputStream; using (var _img = ZipFile.Read(zipStream)) { foreach (var file in _img.Entries) { file.Extract(theePath, ExtractExistingFileAction.OverwriteSilently); Image bmp = Image.FromFile(theePath + "/" + file.FileName); Bitmap mbmp = new Bitmap(bmp); User_Id.AddRange(_coreFunction.DetectAndRecognize(mbmp, path, haarcascades)); } } #endregion #region object to view Bridge _bridge = new Bridge(); _bridge.User_Id = new List<string>(); _bridge.User_Id = User_Id.Distinct(); _bridge.dateSlice = collector.GetValue("dateHoldhidden").AttemptedValue.Split(' '); _bridge.Lecture_Id = Convert.ToInt32(collector.GetValue("Lecture").AttemptedValue); Session["Data"] = _bridge; #endregion return RedirectToActionPermanent("ViewAttendees"); } else if (zip != null) { return RedirectToActionPermanent("ViewAttendees"); } else { return RedirectToActionPermanent("Index"); } }