public ActionResult GetUserValues(string val) { String[] row; var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Users/" + val + ".csv"; if (System.IO.File.Exists(filepath)) //check if user csv file exists { StreamReader readFile = new StreamReader(filepath); String line = readFile.ReadLine(); row = line.Split(','); } else { return(Json(new { Success = "false" })); } ViewBag.Jsonstr = Json(new { Success = "true", Data = new { usertype = row[2] } }); return(Json(new { Success = "true", Data = new { usertype = row[2] } })); //if (row[2] == "Admin") //{ // return Json(new { Success = "true", Data = new { usertype = 1 } }); //} //else //{ // return Json(new { Success = "true", Data = new { usertype = 0 } }); //} }
public ActionResult GetSemesterEvents(string val) { var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Semesters/" + val + ".csv"; Debug.WriteLine(val); String line = ""; if (System.IO.File.Exists(filepath)) //check if user csv file exists { StreamReader readFile = new StreamReader(filepath); line = readFile.ReadLine(); } else { return(Json(new { Success = "false" })); } var retevents = JsonConvert.DeserializeObject <List <EventObject> >(line); //var semesterevents = JsonConvert.DeserializeObject<List<EventObject>>(val); //Debug.WriteLine(retevents[0].name); //filepath = filepath + semesterevents[0].name + ".csv"; //System.IO.File.WriteAllText(filepath, val); //write csv file return(Json(new { Success = "true", Data = retevents })); }
public Microsoft.AspNetCore.Mvc.ActionResult SaveSection(CourseInfo model) { if (ModelState.IsValid) { ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/" + model.sectionSemester + "/" + model.CourseSubject + "_" + model.CourseID + "_" + model.CourseSection + ".csv"; if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); } var csv = model.CourseSubject.ToString() + "," + model.CourseID.ToString() + "," + model.CourseSection.ToString() + "," + model.CourseName.ToString() + "," + model.CreditHours + "," + model.InstructorName.ToString() + "," + model.CampusLocation.ToString() + "," + model.ScheduleAtt.ToString(); //create csv string to write out System.IO.File.WriteAllText(filepath, csv.ToString()); //write csv file } return(RedirectToAction("CreateEditCourse", model)); }
public Microsoft.AspNetCore.Mvc.ActionResult GetCourseValues(string val) { String[] row; StreamReader readFile; string line; var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Courses/" + val + ".csv"; if (System.IO.File.Exists(filepath)) //check if user csv file exists { readFile = new StreamReader(filepath); line = readFile.ReadLine(); if (line != null && line.Contains(',')) { row = line.Split(','); } else { return(Json(new { Success = "false" })); } readFile.Close(); } else { return(Json(new { Success = "false" })); } //ViewBag.reached = 1; if (row.Length == 4) { return(Json(new { Success = "true", Data = new { CourseSubject = row[0], CourseID = row[1], CourseName = row[2], CourseCredit = row[3] } })); } else { return(Json(new { Success = "true", Data = new { CourseSubject = row[0], CourseID = row[1], CourseName = row[2], CourseCredit = row[3], CrossList = row[4] } })); } }
private void GeocodeCsvAddressesFrom(string path, string key) { var amWebClient = new CookieWebClient(); var amBasePath = new ApplicationBasePath( protocolPrefix: "https://", site: "atlas.microsoft.com", applicationPath: "/"); var amClient = new AzureMapsClient( webClient: amWebClient, basePath: amBasePath, subscriptionKey: key); int geocoded = 0; int alreadyGeocode = 0; var addresses = LoadCsvAddresses.LoadFrom(path); foreach (var address in addresses) { if (address.Latitude == null || address.Longitude == null || address.Latitude == 0 || address.Longitude == 0) { var coordinates = new AzureMapsmGeocodeAddress(view, amClient) .Geocode(address); address.Latitude = coordinates.Latitude; address.Longitude = coordinates.Longitude; geocoded++; } else { alreadyGeocode++; } } view.AppendResultText($"\nTotal Addresses: {(geocoded + alreadyGeocode)}"); view.AppendResultText($"\nGeocoded: {geocoded}"); view.AppendResultText($"\nAlready Geocoded (Skipped): {alreadyGeocode}"); var newPath = view.GetFileNameToSaveAs(path, "csv"); if (string.IsNullOrWhiteSpace(newPath)) { // Cancelled view.AppendResultText($"\nGeocoding not saved."); return; } LoadCsvAddresses.SaveTo(addresses, newPath); view.AppendResultText($"\nGeocoding saved to {newPath}"); }
private static AuthorizationClient GetClientThatReturns(string message) { var webClient = new WebClientFake() { DownloadStringReturns = message, }; var path = new ApplicationBasePath("", "", ""); return(new AuthorizationClient(webClient, path)); }
public ActionResult AddSemester(string val) { var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/" + val; System.IO.Directory.CreateDirectory(filepath); filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Semesters/" + val + ".csv"; if (System.IO.File.Exists(filepath)) { return(Json(new { Success = "true" })); } System.IO.File.WriteAllText(filepath, ""); return(Json(new { Success = "true" })); }
public ActionResult GetSectionValues(string val) { var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/" + val + "/"; var files = System.IO.Directory.GetFiles(filepath).Select(Path.GetFileNameWithoutExtension); if (files.Count() > 0) //check if user csv file exists { ViewBag.sections = files; var sections = JsonConvert.SerializeObject(files); return(Json(new { Success = "true", Data = sections })); } return(Json(new { Success = "true" })); }
private AuthorizationClient AuthorizationClient() { var webClient = new CookieWebClient(); var basePath = new ApplicationBasePath( protocolPrefix: "https://", site: options.AlbaHost, applicationPath: "/alba"); var client = new AuthorizationClient( webClient: webClient, basePath: basePath); return(client); }
public ActionResult Index(LoginModel model) { var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Users/" + model.Login + ".csv"; if (System.IO.File.Exists(filepath)) //check if user csv file exists { StreamReader readFile = new StreamReader(filepath); String line = readFile.ReadLine(); String[] row = line.Split(','); if (row[1] == model.Password) //if password is correct { ViewBag.loginname = row[0]; if (row[2] == "0") { HttpContext.Session.SetString(SessionUserType, "Admin"); HttpContext.Session.SetString(SessionUserName, row[0].ToString()); } else if (row[2] == "1") { HttpContext.Session.SetString(SessionUserType, "Editor"); HttpContext.Session.SetString(SessionUserName, row[0].ToString()); } else if (row[2] == "2") { HttpContext.Session.SetString(SessionUserType, "Viewer"); HttpContext.Session.SetString(SessionUserName, row[0].ToString()); } ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); String filepathusers = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Users/"; //get file path for users folder ViewBag.filepathdir = filepathusers; string[] fileEntries = Directory.GetFiles(filepathusers); //get array of files in user directory int pos = filepathusers.LastIndexOf("/") + 1; //get position of last slash var listofusers = fileEntries.Select((r, index) => new System.Web.Mvc.SelectListItem { Text = r.Substring(pos, r.Length - pos - 4), Value = row[2].ToLower() }).ToList(); //populate drop down with list that automatically strips out .csv and the leading directories ViewBag.listusers = listofusers; return(View("HomePage")); } ViewBag.ErrorMessage = "Login or Password incorrect"; return(View("Index")); } else { ViewBag.ErrorMessage = "Login or Password incorrect"; return(View("Index")); } }
/*------------------------------------------------------------------------------------------------------------------*/ public IActionResult CreateEditUser() { ViewBag.debugtext = "test"; ViewBag.Jsonstr = ""; ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session String filepathusers = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Users/"; //get file path for users folder string[] fileEntries = Directory.GetFiles(filepathusers); //get array of files in user directory int pos = filepathusers.LastIndexOf("/") + 1; //get position of last slash var listofusers = fileEntries.Select((r, index) => new System.Web.Mvc.SelectListItem { Text = r.Substring(pos, r.Length - pos - 4), Value = "user" }).ToList(); //populate drop down with list that automatically strips out .csv and the leading directories ViewBag.listusers = listofusers; return(View("CreateEditUser")); }
public ActionResult GetFacultyValues(string val) { String[] row; var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Faculty/" + val + ".csv"; if (System.IO.File.Exists(filepath)) //check if user csv file exists { StreamReader readFile = new StreamReader(filepath); String line = readFile.ReadLine(); row = line.Split(','); } else { return(Json(new { Success = "false" })); } ViewBag.Jsonstr = Json(new { Success = "true", Data = new { factype = row[2] } }); return(Json(new { Success = "true", Data = new { fname = row[0], lname = row[1], factype = row[3], title = row[2] } })); }
public ActionResult LoadSemester(string val, string val2) { var destfilepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/" + val + "/"; var sourcefilepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/" + val2 + "/"; var destsched = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Semesters/" + val + ".csv"; var sourcesched = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Semesters/" + val2 + ".csv"; string[] debugstring = Directory.GetFiles(sourcefilepath, "*.*", SearchOption.AllDirectories); foreach (string files in Directory.GetFiles(sourcefilepath, "*.*", SearchOption.AllDirectories)) { System.IO.File.Copy(files, files.Replace(sourcefilepath, destfilepath), true); } if (System.IO.File.Exists(destsched)) { System.IO.File.Delete(destsched); System.IO.File.Copy(sourcesched, destsched); } //System.IO.File.WriteAllText(filepath, ""); return(Json(new { Success = "true" })); }
/// <summary> /// Connects to Alba and authorizes a user. /// </summary> /// <param name="protocolPrefix">Example: "http://"</param> /// <param name="site">The FQDN name where the Alba applicaton is hosted. Example: www.my-alba-host.com</param> /// <param name="applicationPath">Example: "/alba"</param> public AzureMapsClient( IWebClient webClient, ApplicationBasePath basePath, string subscriptionKey) { if (string.IsNullOrWhiteSpace(subscriptionKey)) { throw new ArgumentNullException(nameof(subscriptionKey)); } if (basePath == null) { throw new ArgumentNullException(nameof(basePath)); } this.webClient = webClient; BasePath = basePath; baseUrl = basePath.BaseUrl; this.subscriptionKey = subscriptionKey; }
public static AuthorizationClient AlbaClient() { string albaHost = Environment.GetEnvironmentVariable("alba_host"); if (string.IsNullOrWhiteSpace(albaHost)) { throw new Exception("ALBA_HOST environment variable is missing!"); } var webClient = new CookieWebClient(); var basePath = new ApplicationBasePath( protocolPrefix: "https://", site: albaHost, applicationPath: "/alba"); var client = new AuthorizationClient( webClient: webClient, basePath: basePath); return(client); }
public IDictionary <string, object> ToJson() { Dictionary <string, object> dictionary = new Dictionary <string, object>(); dictionary.Add(nameof(EnvironmentName), EnvironmentName); // Windows supports forward slashes to easy copy paste and check the path dictionary.Add(nameof(ContentRootPath), ContentRootPath.Replace("\\", "/")); dictionary.Add(nameof(WebRootPath), WebRootPath.Replace("\\", "/")); dictionary.Add(nameof(ApplicationBasePath), ApplicationBasePath.Replace("\\", "/")); dictionary.Add(nameof(AppDirectory), AppDirectory.Replace("\\", "/")); dictionary.Add(nameof(DatabasePath), DatabasePath.Replace("\\", "/")); dictionary.Add(nameof(MainAppDirectoryWebRoot), MainAppDirectoryWebRoot.Replace("\\", "/")); dictionary.Add(nameof(ExecutionPath), ExecutionPath.Replace("\\", "/")); dictionary.Add(nameof(Version), Version); dictionary.Add(nameof(AssemblyPath), AssemblyPath.Replace("\\", "/")); dictionary.Add(nameof(ContextDateTime), ContextDateTime); dictionary.Add(nameof(ComponentDefinition.ComponentId), ComponentInfo?.ComponentId); return(dictionary); }
public Microsoft.AspNetCore.Mvc.ActionResult GetSections(string id) { List <System.Web.Mvc.SelectListItem> items = new List <System.Web.Mvc.SelectListItem>(); string[] parseID = id.Split("?"); //parseID[0] is the semester, parseID[1] is the Subject and courseID "Subj_CourseID" var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "/Data/Schedules/" + parseID[0] + "/"; string[] list = Directory.GetFiles(filepath); int pos = filepath.LastIndexOf("/") + 1; int counter = 0; foreach (string s in list) { if (s.Contains(parseID[1])) { pos = s.LastIndexOf("_") + 1; items.Add(new System.Web.Mvc.SelectListItem() { Text = s.Substring(pos, s.Length - pos - 4), Value = counter.ToString() }); counter++; } } //return new System.Web.Mvc.JsonResult() {Data = items, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return(Json(new { Success = "true", Data = new { items }, JsonRequestBehavior.AllowGet })); }
public Microsoft.AspNetCore.Mvc.ActionResult DeleteSection(CourseInfo model) { ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/" + model.sectionSemester + "/" + model.CourseSubject + "_" + model.CourseID + "_" + model.CourseSection + ".csv"; if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); } return(RedirectToAction("CreateEditCourse", model)); }
/*------------------------------------------------------------------------------------------------------------------*/ public ActionResult CreateEditFaculty() { //if (HttpContext.Session.GetString(SessionUserType) != "Admin" || HttpContext.Session.GetString(SessionUserType) != "Editor") //{ // return View("Index"); //} //var model = new FacultyModel(); ViewBag.debugtext = "create edit faculty"; ViewBag.Jsonstr = ""; ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session String filepathfac = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Faculty/"; //get file path for users folder string[] fileEntries = Directory.GetFiles(filepathfac); //get array of files in user directory int pos = filepathfac.LastIndexOf("/") + 1; //get position of last slash var listoffac = fileEntries.Select((r, index) => new System.Web.Mvc.SelectListItem { Text = r.Substring(pos, r.Length - pos - 4), Value = "fac" }).ToList(); //populate drop down with list that automatically strips out .csv and the leading directories ViewBag.listfac = listoffac; return(View()); }
public Microsoft.AspNetCore.Mvc.ActionResult CreateEditCourse(CourseInfo model, string command) { //IF COURSE SAVE IS PRESSED if (command.Equals("Save Course")) { if (ModelState.IsValid) { ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Courses/" + model.CourseSubject + "_" + model.CourseID + ".csv"; if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); } var csv = model.CourseSubject.ToString() + "," + model.CourseID.ToString() + "," + model.CourseName.ToString() + "," + model.CreditHours; if (model.CrossListWith != null) { csv += "," + model.CrossListWith.ToString(); //create csv string to write out } else { csv += ","; } System.IO.File.WriteAllText(filepath, csv.ToString()); //write csv file } } //ELSE SAVE SECTION IS PRESSED else if (command.Equals("Delete Course")) { ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Courses/" + model.CourseSubject + "_" + model.CourseID + ".csv"; if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); } } else if (command.Equals("Save Section")) { if (ModelState.IsValid) { ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/" + model.sectionSemester + "/" + model.CourseSubject + "_" + model.CourseID + "_" + model.CourseSection + ".csv"; if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); } var csv = ""; if (model.CrossListWith == null) { csv = model.CourseSubject.ToString() + "," + model.CourseID.ToString() + "," + model.CourseSection.ToString() + "," + model.CourseName.ToString() + "," + model.CreditHours + "," + model.InstructorName.ToString() + "," + model.CampusLocation.ToString() + "," + model.ScheduleAtt.ToString() + "," + model.ClassroomSize.ToString() + "," + model.ClassroomType.ToString() + ","; //Empty Crosslist With } else { csv = model.CourseSubject.ToString() + "," + model.CourseID.ToString() + "," + model.CourseSection.ToString() + "," + model.CourseName.ToString() + "," + model.CreditHours + "," + model.InstructorName.ToString() + "," + model.CampusLocation.ToString() + "," + model.ScheduleAtt.ToString() + "," + model.ClassroomSize.ToString() + "," + model.ClassroomType.ToString() + "," + model.CrossListWith.ToString(); } //create csv string to write out System.IO.File.WriteAllText(filepath, csv.ToString()); //write csv file } } else if (command.Equals("Delete Section")) { ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/" + model.sectionSemester + "/" + model.CourseSubject + "_" + model.CourseID + "_" + model.CourseSection + ".csv"; if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); } } return(RedirectToAction("CreateEditCourse", model)); }
public IActionResult CreateEditCourse() { string[] listDetails; string data; string[] directories; int counter = 0; int pos; StreamReader readFile; //CampusLocation Load into model var model = new CourseInfo(); var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/ClassroomData/CampusLocations.csv"; if (System.IO.File.Exists(filepath)) { readFile = new StreamReader(filepath); data = readFile.ReadLine(); if (data != null && data.Contains(',')) { listDetails = data.Split(','); } else { listDetails = new string[0]; } readFile.Close(); } else { listDetails = new string[0]; } foreach (string s in listDetails) { model.CampusNames.Add(new SelectListItem { Value = counter.ToString(), Text = s }); counter++; } //ScheduleType Load into model filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/ClassroomData/ScheduleType.csv"; counter = 0; if (System.IO.File.Exists(filepath)) { readFile = new StreamReader(filepath); data = readFile.ReadLine(); if (data != null && data.Contains(',')) { listDetails = data.Split(','); } else { listDetails = new string[0]; } readFile.Close(); } else { listDetails = new string[0]; } foreach (string s in listDetails) { model.ScheduleType.Add(new SelectListItem { Value = counter.ToString(), Text = s }); counter++; } //Semester Load into model filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/"; directories = Directory.GetDirectories(filepath); counter = 0; foreach (string s in directories) { string[] tmp = s.Split("Schedules/"); model.Semester.Add(new SelectListItem { Value = counter.ToString(), Text = tmp[1] }); counter++; } //Course Subject Load into model filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/ClassroomData/Subject.csv"; counter = 0; if (System.IO.File.Exists(filepath)) { readFile = new StreamReader(filepath); data = readFile.ReadLine(); if (data != null && data.Contains(',')) { listDetails = data.Split(','); } else { listDetails = new string[0]; } readFile.Close(); } else { listDetails = new string[0]; } //THIS IS NEEDED HERE model.SubjectList = new List <System.Web.Mvc.SelectListItem>(); foreach (string s in listDetails) { //TRYING NEW FOR DYNAMIC LOADING model.SubjectList.Add(new System.Web.Mvc.SelectListItem { Value = counter.ToString(), Text = s }); //THIS IS OLD ONE //model.Subject.Add(new CourseSubjectModel { CourseSubjectID = counter, SubjectCode = s }); counter++; } //Course Credit Hours Load into model filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/ClassroomData/CreditHours.csv"; counter = 0; if (System.IO.File.Exists(filepath)) { readFile = new StreamReader(filepath); data = readFile.ReadLine(); if (data != null && data.Contains(',')) { listDetails = data.Split(','); } else { listDetails = new string[0]; } readFile.Close(); } else { listDetails = new string[0]; } foreach (string s in listDetails) { model.CourseCreditList.Add(new SelectListItem { Value = counter.ToString(), Text = s }); counter++; } //Load Classroom Type into Model filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/ClassroomData/ClassroomType.csv"; counter = 0; if (System.IO.File.Exists(filepath)) { readFile = new StreamReader(filepath); data = readFile.ReadLine(); if (data != null && data.Contains(',')) { listDetails = data.Split(','); } else { listDetails = new string[0]; } readFile.Close(); } else { listDetails = new string[0]; } foreach (string s in listDetails) { model.ClassroomTypeList.Add(new SelectListItem { Value = counter.ToString(), Text = s }); counter++; } //Load Faculty into Model filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Faculty/"; counter = 0; listDetails = Directory.GetFiles(filepath); pos = filepath.LastIndexOf("/") + 1; foreach (string s in listDetails) { model.ListOfInstructors.Add(new SelectListItem { Value = counter.ToString(), Text = s.Substring(pos, s.Length - pos - 4) }); counter++; } ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); return(View(model)); }
/// <summary> /// Connects to Alba and authorizes a user. /// </summary> /// <param name="protocolPrefix">Example: "http://"</param> /// <param name="site">The FQDN name where the Alba applicaton is hosted. Example: www.my-alba-host.com</param> /// <param name="applicationPath">Example: "/alba"</param> public NominatimClient(IWebClient webClient, ApplicationBasePath basePath) { this.webClient = webClient; BasePath = basePath; baseUrl = basePath.BaseUrl; }
public IActionResult CreateEditSchedule() { string[] listDetails; string data; string[] directories; int counter = 0; //CampusLocation Load into model var model = new CourseInfo(); var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/ClassroomData/CampusLocations.csv"; if (System.IO.File.Exists(filepath)) { StreamReader readFile = new StreamReader(filepath); data = readFile.ReadLine(); listDetails = data.Split(','); } else { listDetails = new string[0]; } foreach (string s in listDetails) { model.CampusNames.Add(new System.Web.Mvc.SelectListItem { Value = counter.ToString(), Text = s }); counter++; } //ScheduleType Load into model filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/ClassroomData/ScheduleType.csv"; counter = 0; if (System.IO.File.Exists(filepath)) { StreamReader readFile = new StreamReader(filepath); data = readFile.ReadLine(); listDetails = data.Split(','); } else { listDetails = new string[0]; } foreach (string s in listDetails) { model.ScheduleType.Add(new System.Web.Mvc.SelectListItem { Value = counter.ToString(), Text = s }); counter++; } //Semester Load into model filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/"; directories = Directory.GetDirectories(filepath); counter = 0; foreach (string s in directories) { string[] tmp = s.Split("Schedules/"); model.Semester.Add(new System.Web.Mvc.SelectListItem { Value = counter.ToString(), Text = tmp[1] }); counter++; } //Course Subject Load into model filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Courses/"; counter = 0; foreach (string s in Directory.GetFiles(filepath)) { var path = Path.GetFileNameWithoutExtension(s); //<<<<<<< HEAD //model.CourseList.Add(new ListOfCourses { CourseNumberID = fileCounter, CourseNameFromFile = path });//CourseNameFromFile = s.Remove(s.Length-4)}); //======= //model.CourseList.Add(new ListOfCourses { CourseNumberID = counter, CourseNameFromFile = path });//CourseNameFromFile = s.Remove(s.Length-4)}); //>>>>>>> J-branch } ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); return(View(model)); } //createeditschedule
public ActionResult CheckConflicts(string val) { if (val != "[]") { //schedule file path var schedfilepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Semesters/" + val + ".csv"; //read in the schedule and convert to list of eventobjects var schedevents = JsonConvert.DeserializeObject <List <EventObject> >(val); //section file path var sectionfilepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/" + schedevents[0].name + "/"; //create list of SectionObject for checking List <SectionObject> SchedSections = new List <SectionObject>(); List <ErrorObject> Errorlist = new List <ErrorObject>(); var ProfCount = new Dictionary <string, int>(); foreach (EventObject schedevent in schedevents) { string[] currentsection = new StreamReader(sectionfilepath + schedevent.title + ".csv").ReadLine().Split(","); string[] currentteacher = new StreamReader(ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Faculty/" + currentsection[5] + "," + currentsection[6] + ".csv").ReadLine().Split(","); SectionObject tempsect = new SectionObject(); tempsect.start = schedevent.start; tempsect.end = schedevent.end; tempsect.title = schedevent.title; tempsect.teacher = currentsection[5] + "," + currentsection[6]; switch (currentteacher[3]) { case "0": tempsect.maxteacherclasses = 2; break; case "1": tempsect.maxteacherclasses = 4; break; case "2": tempsect.maxteacherclasses = 5; break; } //tempsect.maxteacherclasses = currentteacher[2]; tempsect.campus = currentsection[7]; tempsect.crosslist = currentsection[11]; SchedSections.Add(tempsect); //maintain count of classes taught by teachers if (ProfCount.ContainsKey(tempsect.teacher)) { ProfCount[tempsect.teacher] += 1; } else { ProfCount.Add(tempsect.teacher, 1); } } for (int i = 0; i < SchedSections.Count; i++) { for (int j = 0; j < SchedSections.Count; j++) { if (i != j) { //check for same teacher teaching at same time and classes aren't crosslisted Debug.Write("we are in the loop"); if ((SchedSections[i].start >= SchedSections[j].start && SchedSections[i].start <= SchedSections[j].end && SchedSections[i].teacher == SchedSections[j].teacher && !SchedSections[i].title.ToUpper().Contains(SchedSections[j].crosslist.ToUpper()) && !SchedSections[j].title.ToUpper().Contains(SchedSections[i].crosslist.ToUpper())) || (SchedSections[j].start >= SchedSections[i].start && SchedSections[j].start <= SchedSections[i].end && SchedSections[i].teacher == SchedSections[j].teacher && !SchedSections[i].title.ToUpper().Contains(SchedSections[j].crosslist.ToUpper()) && !SchedSections[j].title.ToUpper().Contains(SchedSections[i].crosslist.ToUpper())))// || (SchedSections[i].start >= SchedSections[j].start && SchedSections[i].teacher == SchedSections[j].teacher)) //&& SchedSections[i].title.IndexOf(SchedSections[j].crosslist, StringComparison.OrdinalIgnoreCase) >= 0) { Errorlist.Add(new ErrorObject { startclass1 = SchedSections[i].start, startclass2 = SchedSections[j].start, class1title = SchedSections[i].title, class2title = SchedSections[j].title, teacher = SchedSections[i].teacher, errordesc = SchedSections[i].teacher + " is the same for these classes at the same time" }); } } // } if (ProfCount[SchedSections[i].teacher] > SchedSections[i].maxteacherclasses) { int errorfound = 0; for (int k = 0; k < Errorlist.Count(); k++) { if (Errorlist[k].errordesc == SchedSections[i].teacher + " is teaching more than " + SchedSections[i].maxteacherclasses + " classes") { errorfound = 1; break; } } if (errorfound == 0) { Errorlist.Add(new ErrorObject { startclass1 = new DateTime(), startclass2 = new DateTime(), class1title = null, class2title = null, teacher = SchedSections[i].teacher, errordesc = SchedSections[i].teacher + " is teaching more than " + SchedSections[i].maxteacherclasses + " classes" }); } } SchedSections.RemoveAt(i); } var returnjson = JsonConvert.SerializeObject(Errorlist); return(Json(new { Success = "true", Data = returnjson })); } return(Json(new { Success = "true", Data = "" })); }
public ActionResult SaveSemesterValues(string val, string val2) { var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Semesters/"; //Debug.WriteLine(val); var semesterevents = JsonConvert.DeserializeObject <List <EventObject> >(val); //Debug.WriteLine(semesterevents[0].name); if (val == "[]") { filepath = filepath + val2 + ".csv"; if (System.IO.File.Exists(filepath)) //check if user csv file exists { System.IO.File.Delete(filepath); //delete user file if it exists } System.IO.File.WriteAllText(filepath, val); //write csv file var expfilepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "wwwroot/Export/" + val2 + ".csv"; if (System.IO.File.Exists(expfilepath)) //check if user csv file exists { System.IO.File.Delete(expfilepath); //delete user file if it exists } System.IO.File.WriteAllText(expfilepath, ""); } if (semesterevents.Count > 0) { filepath = filepath + semesterevents[0].name + ".csv"; if (System.IO.File.Exists(filepath)) //check if user csv file exists { System.IO.File.Delete(filepath); //delete user file if it exists } System.IO.File.WriteAllText(filepath, val); //write csv file //create export file (csv that opens in excel) List <string> export = new List <string>(); export.Add("Subject,ID,Section,Title,Credit Hours,Professor Last Name,Professor First Name,Campus,Type,Size,Classroom Type,Crosslist,Day of Week, Start Time of Day, End Time of Day,"); String current_input = ""; var expfilepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "wwwroot/Export/" + semesterevents[0].name + ".csv"; if (System.IO.File.Exists(expfilepath)) //check if user csv file exists { System.IO.File.Delete(expfilepath); //delete user file if it exists } for (int i = 0; i < semesterevents.Count; i++) { String current_file_path = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Schedules/" + semesterevents[0].name + "/" + semesterevents[i].title + ".csv"; if (System.IO.File.Exists(current_file_path)) { //correct time zone difference semesterevents[i].start = semesterevents[i].start.AddHours(-4); semesterevents[i].end = semesterevents[i].end.AddHours(-4); //DateTime test = semesterevents[i].start.AddHours(-4); StreamReader readFile = new StreamReader(current_file_path); current_input = readFile.ReadLine() + "," + semesterevents[i].start.DayOfWeek + "," + semesterevents[i].start.TimeOfDay + "," + semesterevents[i].end.TimeOfDay; int indexofclass = export.FindIndex(x => x.StartsWith(current_input.Substring(0, 12))); if (indexofclass >= 0) { // export[indexofclass] = export[indexofclass] + "," + semesterevents[i].start.DayOfWeek + "," + semesterevents[i].start.TimeOfDay + "," + semesterevents[i].end.TimeOfDay; continue; } export.Add(current_input); } } System.IO.File.WriteAllLines(expfilepath, export); //write csv file } return(Json(new { Success = "true" })); }
public ActionResult CreateEditUser(UserModel model, string CreateEdit) { String filepathusers = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Users/"; //get file path for users folder string[] fileEntries = Directory.GetFiles(filepathusers); //get array of files in user directory int pos = filepathusers.LastIndexOf("/") + 1; //get position of last slash var listofusers = fileEntries.Select((r, index) => new System.Web.Mvc.SelectListItem { Text = r.Substring(pos, r.Length - pos - 4), Value = "user" }).ToList(); //populate drop down with list that automatically strips out .csv and the leading directories ViewBag.listusers = listofusers; //ViewBag.debugtext = "Entered createedituser after button"; switch (CreateEdit) { case "Create/Edit": if (model.IsValid(model.Username, model.Password)) { //ViewBag.debugtext = "entered createedit case"; ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session var usertype = ""; var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Users/" + model.Username + ".csv"; //get absolute file path for possible user file if (System.IO.File.Exists(filepath)) //check if user csv file exists { System.IO.File.Delete(filepath); //delete user file if it exists } if (model.Type == 0) //get text value of user type { usertype = "0"; } else if (model.Type == 1) { usertype = "1"; } else { usertype = "2"; } if (model.Password == null) { model.Password = ""; } var csv = model.Username.ToString() + "," + model.Password.ToString() + "," + usertype; //create csv string to write out System.IO.File.WriteAllText(filepath, csv.ToString()); //write csv file filepathusers = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Users/"; //get file path for users folder fileEntries = Directory.GetFiles(filepathusers); //get array of files in user directory pos = filepathusers.LastIndexOf("/") + 1; //get position of last slash listofusers = fileEntries.Select((r, index) => new System.Web.Mvc.SelectListItem { Text = r.Substring(pos, r.Length - pos - 4), Value = "user" }).ToList(); //populate drop down with list that automatically strips out .csv and the leading directories ViewBag.listusers = listofusers; return(View("CreateEditUser")); } break; case "Delete": //ViewBag.debugtext = "entered delete case"; ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session filepathusers = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Users/" + model.Username + ".csv"; //get absolute file path for possible user file if (System.IO.File.Exists(filepathusers)) //check if user csv file exists { System.IO.File.Delete(filepathusers); //delete user file if it exists } filepathusers = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Users/"; //get file path for users folder fileEntries = Directory.GetFiles(filepathusers); //get array of files in user directory pos = filepathusers.LastIndexOf("/") + 1; //get position of last slash listofusers = fileEntries.Select((r, index) => new System.Web.Mvc.SelectListItem { Text = r.Substring(pos, r.Length - pos - 4), Value = "user" }).ToList(); //populate drop down with list that automatically strips out .csv and the leading directories ViewBag.listusers = listofusers; return(View()); default: //ViewBag.debugtext = "entered default"; return(View()); } ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); return(View()); }
/// <summary> /// Connects to Alba and authorizes a user. /// </summary> /// <param name="protocolPrefix">Example: "http://"</param> /// <param name="site">The FQDN name where the Alba applicaton is hosted. Example: www.my-alba-host.com</param> /// <param name="applicationPath">Example: "/alba"</param> public AuthorizationClient(IWebClient webClient, ApplicationBasePath basePath) { this.webClient = webClient; BasePath = basePath; }
//[HttpGet("[controller]/[action]")] public ActionResult CreateEditFaculty(FacultyModel model, string CreateEdit) { String filepathfac = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Faculty/"; //get file path for faculty folder string[] fileEntries = Directory.GetFiles(filepathfac); //get array of files in user directory int pos = filepathfac.LastIndexOf("/") + 1; //get position of last slash var listoffac = fileEntries.Select((r, index) => new System.Web.Mvc.SelectListItem { Text = r.Substring(pos, r.Length - pos - 4), Value = "fac" }).ToList(); //populate drop down with list that automatically strips out .csv and the leading directories ViewBag.listfac = listoffac; ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); ViewBag.debugtext = "entered createeditfacutly"; if (model.IsValid(model.Facultyfname, model.Facultylname, model.Facultytitle, model.Facultytype)) { switch (CreateEdit) { case "CreateEdit": ViewBag.debugtext = "entered create case"; ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session var factype = ""; var filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Faculty/" + model.Facultylname + "," + model.Facultyfname + ".csv"; //get absolute file path for possible user file if (System.IO.File.Exists(filepath)) //check if user csv file exists { System.IO.File.Delete(filepath); //delete user file if it exists } if (model.Facultytype == 0) //get text value of user type { factype = "0"; } else if (model.Facultytype == 1) { factype = "1"; } else { factype = "2"; } var csv = model.Facultyfname.ToString() + "," + model.Facultylname + "," + model.Facultytitle.ToString() + "," + factype; //create csv string to write out System.IO.File.WriteAllText(filepath, csv.ToString()); //write csv file filepathfac = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Faculty/"; //get file path for faculty folder fileEntries = Directory.GetFiles(filepathfac); //get array of files in user directory pos = filepathfac.LastIndexOf("/") + 1; //get position of last slash listoffac = fileEntries.Select((r, index) => new System.Web.Mvc.SelectListItem { Text = r.Substring(pos, r.Length - pos - 4), Value = "fac" }).ToList(); //populate drop down with list that automatically strips out .csv and the leading directories ViewBag.listfac = listoffac; return(View()); case "Delete": ViewBag.debugtext = "entered delete case"; ViewBag.sessiontype = HttpContext.Session.GetString(SessionUserType); //get type of user from session ViewBag.loginname = HttpContext.Session.GetString(SessionUserName); //get username from session filepath = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Faculty/" + model.Facultylname + "," + model.Facultyfname + ".csv"; //get absolute file path for possible user file if (System.IO.File.Exists(filepath)) //check if user csv file exists { System.IO.File.Delete(filepath); //delete user file if it exists } filepathfac = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Faculty/"; //get file path for faculty folder fileEntries = Directory.GetFiles(filepathfac); //get array of files in user directory pos = filepathfac.LastIndexOf("/") + 1; //get position of last slash listoffac = fileEntries.Select((r, index) => new System.Web.Mvc.SelectListItem { Text = r.Substring(pos, r.Length - pos - 4), Value = "fac" }).ToList(); //populate drop down with list that automatically strips out .csv and the leading directories ViewBag.listfac = listoffac; return(View()); default: ViewBag.debugtext = "entered default case"; filepathfac = ApplicationBasePath.ToString().Substring(0, ApplicationBasePath.ToString().Length - 24) + "Data/Faculty/"; //get file path for faculty folder fileEntries = Directory.GetFiles(filepathfac); //get array of files in user directory pos = filepathfac.LastIndexOf("/") + 1; //get position of last slash listoffac = fileEntries.Select((r, index) => new System.Web.Mvc.SelectListItem { Text = r.Substring(pos, r.Length - pos - 4), Value = "fac" }).ToList(); //populate drop down with list that automatically strips out .csv and the leading directories ViewBag.listfac = listoffac; return(View()); } } return(View()); }