public OperationResponse AddNew(Student student) { var response = new OperationResponse(); try { response.HasError = !StudentMapper.Insert(student); } catch (Exception ex) { response.HasError = true; response.Message = ex.ToString(); } return(response); }
public IActionResult UpdateStudent([FromBody] StudentViewModel studentView) { try { var idUser = User.GetUserId(); var studentId = _studentService.GetStudentIdForUser(idUser); var student = StudentMapper.ToActualObject(studentView); student.Id = studentId; _studentService.UpdateStudent(student); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok()); }
public OperationResponse Hide(long id) { var response = new OperationResponse(); try { response.HasError = !StudentMapper.Hide(id); } catch (Exception ex) { response.HasError = true; response.Message = ex.ToString(); } return(response); }
// GET: Home public ActionResult Index() { var students = new CRUDContext().Students.Include(x => x.Address).ToList(); //(from s in new CRUDContext().Students.Include(x => x.Address) // select s).ToList(); List <StudentModel> studentModels = new List <StudentModel>(); foreach (Student s in students) { studentModels.Add(StudentMapper.ContextToModel(s)); } ViewBag.Students = studentModels; return(View()); }
protected Pair ProcessRow(Pair pair, MySqlDataReader Reader) { pair.ID = Reader.GetInt32(0); pair.Number_of_guests = Reader.GetInt32(1); StudentMapper studentmapper = new StudentMapper(MysqlDb.GetInstance()); pair.Student1_id = Reader.GetInt32(2); try { pair.Student2_id = Reader.GetInt32(3); } catch (Exception e) { pair.Student2_id = 0; } return(pair); }
private void buttonResetAccount_Click(object sender, EventArgs e) { //After a warning, the student's progress is reset to 0 if (MessageBox.Show("Είστε βέβαιοι ότι θέλετε να επαναφέτε την πρόοδο του λογαριασμού σας?", "Επαναφορά προόδου;", MessageBoxButtons.YesNo) == DialogResult.Yes) { activeStudent.Level = 1; activeStudent.StudentProgress.FinalExam = 0; for (int i = 0; i < 10; i++) { activeStudent.StudentProgress.PropaideiaProgress[i] = 0; } StudentMapper.Update(activeStudent); MessageBox.Show("Ο λογαριασμός σας έχει επαναφερθεί! Θα μεταφερθείτε στην οθόνη σύνδεσης!", "Επαναφορά Λογαριασμού", MessageBoxButtons.OK); this.Hide(); LoginScreen loginForm = new LoginScreen(); loginForm.Show(); } }
private async Task <List <FullStudent> > GetAllFullStudents() { //CosmosConnector dbConnector = new CosmosConnector("https://localhost:8081", "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="); var url = UtilityFunctions.UtilityFunctions.GetValueOfSetting("cosmosUrl"); var accessKey = UtilityFunctions.UtilityFunctions.GetValueOfSetting("cosmosAccessKey"); CosmosConnector dbConnector = new CosmosConnector(url, accessKey); dbConnector.PreviousDatabaseName = "StudentDatabase"; dbConnector.PreviousTableName = "StudentRecords"; var records = await dbConnector.GetStudentRecords(); List <FullStudent> fullStudents = new List <FullStudent>(); foreach (var record in records) { var dict = (IDictionary <string, object>)record; FullStudent fullStudent = StudentMapper.DictionaryObjectToFullStudent(dict); //FullStudent fullStudent = new FullStudent() //{ // FirstName = dict["FirstName"] as string, // MiddleName = dict["MiddleName"] as string, // LastName = dict["LastName"] as string, // DateOfBirth = (DateTime)dict["DateOfBirth"], // Organization = dict["Organization"] as string, // SchoolDivision = dict["SchoolDivision"] as string, // Degree = dict["Degree"] as string, // Awarded = (DateTime)dict["Awarded"], // Major = dict["Major"] as string, // PreviousRecordHash = dict["PreviousRecordHash"] as string, // CurrentNodeHash = dict["CurrentNodeHash"] as string, // Salt = dict["Salt"] as string, // RecordId = Convert.ToInt32(dict["RecordId"]) //}; fullStudents.Add(fullStudent); } return(fullStudents); }
public StudentsResponse GetPaginatedList(DateTime startDate, DateTime endDate, string name, bool isEnabled, string gender, string type, int pageNumber, int pageSize, string sortBy, string sortDirection) { var listResult = new List <Student>(); long totalItems = 0; long totalPages = 0; try { string filter = string.Empty; string joinOperator = string.Empty; //filter = " convert(date, updated_on) between '" + startDate.ToString("yyyyMMdd") + "' and '" + endDate.ToString("yyyyMMdd") + "' "; filter = " updated_on >= '" + startDate.ToString("yyyy-MM-dd") + "' and updated_on <= '" + endDate.ToString("yyyy-MM-dd") + "' + INTERVAL 1 DAY "; if (!string.IsNullOrEmpty(name)) { filter += " and name like '%" + name + "%'"; } if (!string.IsNullOrEmpty(gender)) { filter += " and gender = '" + gender + "'"; } joinOperator = (string.IsNullOrEmpty(filter) ? string.Empty : " and "); if (!string.IsNullOrEmpty(type)) { filter += " and type = '" + type + "'"; } listResult = StudentMapper.GetAllPaginatedWhere(pageNumber, pageSize, out totalItems, out totalPages, filter, sortBy, sortDirection, isEnabled); } catch (Exception ex) { Logger.Create().Exception(ex); } return(new StudentsResponse { Students = listResult, TotalStudents = totalItems, TotalPages = totalPages }); }
public IActionResult AllStudents() { var students = _dbContex.Students .Include(s => s.Applicant) .Include(s => s.StudentLessons) .ThenInclude(sl => sl.Lesson) .ThenInclude(l => l.Teacher) .Include(s => s.StudentLessons) .ThenInclude(sl => sl.Lesson) .ThenInclude(l => l.Technology); List <StudentInfoViewModel> model = new List <StudentInfoViewModel>(); foreach (var item in students) { model.Add(StudentMapper.Mapping(item)); } return(View(model)); }
private void buttonRegister_Click(object sender, EventArgs e) { if (!labelRegisterName.Visible) //First button click shows the rest of the fields that need to be filled in { labelRegisterName.Visible = true; labelRegisterSurname.Visible = true; textBoxRegisterName.Visible = true; textBoxRegisterSurname.Visible = true; } else //After the rest of the fields are visible, the register button tries to register the user in the DB { if (!String.IsNullOrEmpty(textBoxUsername.Text) && !String.IsNullOrEmpty(textBoxPassword.Text) && !String.IsNullOrEmpty(textBoxRegisterName.Text) && !String.IsNullOrEmpty(textBoxRegisterSurname.Text)) { Student newStudent = new Student(textBoxUsername.Text, textBoxRegisterName.Text, textBoxRegisterSurname.Text); if (StudentMapper.Get(newStudent.Username) == null) //If the student doesn't already exist { if (StudentMapper.Insert(newStudent, textBoxPassword.Text)) { if (MessageBox.Show("Ο χρήστης εγγράφηκε επιτυχώς!", "Επιτυχής Εγγραφή!", MessageBoxButtons.OK) == DialogResult.OK) { //auto login after register buttonLogin.PerformClick(); } } else { MessageBox.Show("Υπήρξε ένα σφάλμα κατά την δημιουργία του χρήστη!", "Σφάλμα", MessageBoxButtons.OK); } } else { MessageBox.Show("Υπάρχει ήδη ένας χρήστης με αυτό το όνομα χρήστη!", "Σφάλμα", MessageBoxButtons.OK); } } else { MessageBox.Show("Παρακαλούμε συμπληρώστε όλα τα παραπάνω πεδιά πριν συνεχίσετε!", "Σφάλμα", MessageBoxButtons.OK); } } }
private async Task <List <FullStudent> > GetAllFullStudents() { var url = UtilityFunctions.UtilityFunctions.GetValueOfSetting("cosmosUrl"); var accessKey = UtilityFunctions.UtilityFunctions.GetValueOfSetting("cosmosAccessKey"); IDatabaseConnector dbConnector = new CosmosConnector(url, accessKey); dbConnector.PreviousDatabaseName = "StudentDatabase"; dbConnector.PreviousTableName = "StudentRecords"; var records = await dbConnector.GetStudentRecords(); List <FullStudent> fullStudents = new List <FullStudent>(); foreach (var record in records) { var dict = (IDictionary <string, object>)record; FullStudent fullStudent = StudentMapper.DictionaryObjectToFullStudent(dict); fullStudents.Add(fullStudent); } return(fullStudents); }
private void buttonUpdateName_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(textBoxChangeName.Text) && !String.IsNullOrEmpty(textBoxChangeSurname.Text) && Regex.IsMatch(textBoxChangeName.Text, @"^[a-zA-Z]+$") && Regex.IsMatch(textBoxChangeSurname.Text, @"^[a-zA-Z]+$")) { //Change name and surname of a temp user and if StudentMapper. Update succeeds we replace the activeStudent with it Student tempStudent = activeStudent; tempStudent.Name = textBoxChangeName.Text; tempStudent.Surname = textBoxChangeSurname.Text; if (StudentMapper.Update(tempStudent)) { activeStudent = tempStudent; MessageBox.Show("Τα στοιχεία του λογαριασμού σας ενημερώθηκαν επιτυχώς!", "Ο λογαριασμός ενημερώθηκε επιτυχώς", MessageBoxButtons.OK); } else { MessageBox.Show("Η αλλαγή των στοιχείων του μαθητή απέτυχε!", "Σφάλμα", MessageBoxButtons.OK); } } else { MessageBox.Show("Παρακαλούμε πληκτρολογήστε ένα έγκυρο όνομα/επώνυμο!", "Ειδοποίηση", MessageBoxButtons.OK); } }
public ActionResult Register(StudentModel studentModel) { try { CRUDContext db = new CRUDContext(); if (studentModel.Id > 0) { Student student = db.Students.Include(x => x.Address).Where(x => x.Id == studentModel.Id).FirstOrDefault(); student.Email = studentModel.Email; student.Name = studentModel.Name; db.Entry(student).State = EntityState.Modified; } else { db.Students.Add(StudentMapper.ModelToContext(studentModel)); } db.SaveChanges(); var students = new CRUDContext().Students.Include(x => x.Address).ToList(); List <StudentModel> studentModels = new List <StudentModel>(); foreach (Student s in students) { studentModels.Add(StudentMapper.ContextToModel(s)); } return(Json(studentModels, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(e.Message, JsonRequestBehavior.AllowGet)); } return(Json(false, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Import a CSV file existing on disk, the path of the file to import could be provided by the console call as an argument or could be read from the program. Once validated that we can access the file all students are validated and verified if they don't already exists on the database, the if any student could be imported is saved if the users wants. /// </summary> /// <param name="path">Path of the file to import provided as an argument at execution time</param> private static void ImportCSVFile(string path = "") { if (string.IsNullOrEmpty(path)) { Console.WriteLine("Please introduce the path of the CSV file which contains the students to load: "); path = Console.ReadLine(); } if (File.Exists(path) && Path.GetExtension(path) == ".csv") { var content = File.ReadAllLines(path); if (content != null && content.Length > 0) { bool hasErrors = false; bool hasDuplicates = false; var currentStudents = StudentMapper.GetAllWhere(string.Empty); currentStudents.Sort(); var studentsToImport = new List <Student>(); int errorCount = 0; for (int position = 0; position < content.Length; position++) { string[] parts = content[position].Split(','); if (parts.Length == 4) { StudentType type = StudentType.Elementary; bool validType = Enum.TryParse(parts[0].ToString(), out type); DateTime updatedOn = DateTime.Now; bool validDateTime = DateTime.TryParseExact(parts[3], "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out updatedOn); string name = null; if (parts[1] != null) { name = parts[1].Trim(); } string gender = null; if (parts[2] != null) { gender = parts[2].Trim().ToUpper(); } if (validType && validDateTime && !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(gender) && (gender == "M" || gender == "F")) { Student student = new Student(); student.Type = type; student.Name = name; student.Gender = gender == "M" ? "Male" : "Female"; student.Enabled = true; student.UpdatedOn = updatedOn; if (!currentStudents.Contains(student, new StudentsComparer())) { studentsToImport.Add(student); } else { string msg = string.Format("There is a duplicated student in row {0}. Please verify the data if you want before import.", position + 1); if (errorCount < MaxImportErrorsToShow) { Console.WriteLine(msg); Logger.Create().Message(msg); } hasDuplicates = true; errorCount++; } } else { string msg = string.Format("There is an error with your data in row {0}. Please verify that the Type is (Kinder, Elementary, High, University), The name is not empty, Gender is M(Male) or F(Female) and you placed a valid time stamp in the following format <year><month><day><hour><minute><second> for example the representation for December 31st, 2013 14:59:34 is 20131231145934. All this FOUR values must be in a valid CSV format.", position + 1); if (errorCount < MaxImportErrorsToShow) { Console.WriteLine(msg); Logger.Create().Message(msg); } hasErrors = true; errorCount++; } } else { string msg = string.Format("There is an error with your data in row {0}. Please verify that the Type is (Kinder, Elementary, High, University), The name is not empty, Gender is M(Male) or F(Female) and you placed a valid time stamp in the following format <year><month><day><hour><minute><second> for example the representation for December 31st, 2013 14:59:34 is 20131231145934. All this FOUR values must be in a valid CSV format.", position + 1); if (errorCount < MaxImportErrorsToShow) { Console.WriteLine(msg); Logger.Create().Message(msg); } hasErrors = true; errorCount++; } if (position % 10000 == 0) { Console.WriteLine("We are processing your data, please wait ..."); } } //End of the processing CSV file string message = string.Empty; if (hasErrors) { message += "We found some errors processing your file, above we show some of them. "; } if (hasDuplicates) { message += "We found some duplicated students when processing your file, above we show some of them."; } if (studentsToImport.Count > 0) { if (!string.IsNullOrEmpty(message)) { Console.WriteLine(message + string.Format(" The total of errors/duplicates found was {0}. Even if you have errors and duplicates we found some students which can be imported.", errorCount)); } Console.WriteLine(string.Format("You have {0} students to import, do you wish to insert them to the database? (Y/N) [Y]: ", studentsToImport.Count)); string answer = Console.ReadLine(); if (string.IsNullOrEmpty(answer) || answer[0].ToString().ToUpper() == "Y") { int count = 0; foreach (var student in studentsToImport) { if (StudentMapper.InsertFull(student)) { count++; if (count % 10000 == 0) { Console.WriteLine("We are saving your data, please wait ..."); } } else { Logger.Create().Message("We couldn't save the student: " + student.ToString()); } } ShowContinueMessage(string.Format("{0} students were saved of {1}. {2}", count, studentsToImport.Count, (count < studentsToImport.Count ? "Some students were not saved, please review the log file to see more details." : ""))); } else { if (!string.IsNullOrEmpty(answer) && !(answer[0].ToString().ToUpper() == "Y" || answer[0].ToString().ToUpper() == "N")) { ShowContinueMessage("You should choose Y for yes or N for no, please try again."); } } } else { ShowContinueMessage(message + " After the processing of your file we couldn't find any students to import, please review your data and try again."); } } else { ShowContinueMessage("We couldn't read anything from your file, please check it and try again"); } } else { ShowContinueMessage("Please verify your path and try again, be sure to provide a valid CSV file!"); } }
public StudentDAO GetStudentByID(int id) { return(StudentMapper.MapToStudentDAO(GetData.GetStudentByID(id))); }
/// <summary> /// Shows a paginated in memory list of students and provides simple commands to navigate trough the list of students. /// This method populates the global student's list applying the current SQL filter set. /// </summary> private static void ShowStudents() { students = StudentMapper.GetAllWhere(currentSqlFilter, currentFieldSort, currentSortDir, true); if (students != null) { int page = 1; int itemsPage = 10; string navOption = string.Empty; int total = students.Count / itemsPage; if (students.Count % itemsPage > 0) { total++; } while (string.IsNullOrEmpty(navOption) || navOption != "Q") { Console.Clear(); string msg = "==== List of Students ===="; Console.WriteLine(Environment.NewLine + "{0," + ((Console.WindowWidth / 2) + msg.Length / 2) + "}" + Environment.NewLine, msg); PrintLine(); PrintRow("ID", "Name", "Gender", "Type", "Last Update"); PrintLine(); for (int i = 10 * (page - 1); i < students.Count && i < 10 * page; i++) { var student = students[i]; PrintRow(student.Id.ToString(), student.Name, student.Gender, student.Type.ToString(), student.UpdatedOn.ToString("MM-dd-yyyy HH:mm")); PrintLine(); } Console.WriteLine(string.Format("You are seeing page {0} of {1}, select one of the following options: " + Environment.NewLine + "(N)ext, (P)revious, (F)irst, (L)ast, (E)xport to CSV, (Q)uit to main menu; " + Environment.NewLine + "introducing the letter enclosed in parenthesis and hitting enter: ", page, total)); navOption = Console.ReadLine(); if (!string.IsNullOrEmpty(navOption)) { navOption = navOption[0].ToString().ToUpper(); switch (navOption) { case "N": page++; if (page > total) { page = 1; } break; case "P": page--; if (page < 1) { page = total; } break; case "F": page = 1; break; case "L": page = total; break; case "E": if (!ExportToCSV()) { ShowContinueMessage("We could not export the current list of students please review previous messages and logs, and try again."); } break; } } } } else { ShowContinueMessage("There are no students to show."); } }
/// <summary> /// Entry point of the console application which presents a menu of options to do all the CRUD operations over the students table /// </summary> /// <param name="args">List of arguments which can be applied to the console client at the time of execution which can be the name of CSV file to import and given filter in the format expected: /// Ex: CmdClient.exe Test.csv name=leia /// Ex: CmdClient.exe Test.csv type=Kinder /// Ex: CmdClient.exe Test.csv type=Elementary gender=female /// </param> static void Main(string[] args) { //Setting background and color Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.DarkBlue; Console.Clear(); //Reading the connection string from app.settings DBConnection.ConnectionString = ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString; //Verifying if some arguments were passed to the program and processing them if (args.Length > 0) { ImportCSVFile(args[0]); DefineFilter(args); if (!string.IsNullOrEmpty(currentFilter)) { ShowStudents(); } } //Showing the menu and doing the main logic of the program char option = '\0'; while (option != '9') { Console.Clear(); Console.WriteLine("===================== Console Students Administration ====================="); Console.WriteLine("1. Load students from CSV"); Console.WriteLine("2. Define a filter to show students"); Console.WriteLine("3. Clear current filter"); Console.WriteLine("4. Show students"); Console.WriteLine("5. Create new student"); Console.WriteLine("6. Edit student"); Console.WriteLine("7. Hide student"); Console.WriteLine("8. Delete student"); Console.WriteLine("9. Quit"); Console.WriteLine("Please choose an option number from 1 to 9 and press Enter: "); var userInput = Console.ReadLine(); if (!string.IsNullOrEmpty(userInput)) { option = userInput[0]; switch (option) { case '1': ImportCSVFile(); break; case '2': DefineFilter(); break; case '3': if (string.IsNullOrEmpty(currentFilter)) { ShowContinueMessage("There isn't set any filter right now."); } else { Console.WriteLine(Environment.NewLine + "CURRENT filter is: " + currentFilter); Console.WriteLine("Are you sure that do you want to clear it? (Y/N) [Y]: "); string answer = Console.ReadLine(); if (string.IsNullOrEmpty(answer) || answer[0].ToString().ToUpper() == "Y") { currentFilter = string.Empty; currentSqlFilter = string.Empty; currentFieldSort = "updated_on"; currentSortDir = "DESC"; } } break; case '4': ShowStudents(); break; case '5': CreateStudent(); break; case '6': EditStudent(); break; case '7': var student = GetStudent(); if (student != null) { Console.WriteLine(string.Format("Are you sure that you want to HIDE the student: {0}? (Y/N) [Y]: ", student.ToString())); string value = Console.ReadLine(); if (string.IsNullOrEmpty(value) || value[0].ToString().ToUpper() == "Y") { StudentMapper.Hide(student.Id); } else { if (!string.IsNullOrEmpty(value) && !(value[0].ToString().ToUpper() == "Y" || value[0].ToString().ToUpper() == "N")) { ShowContinueMessage("You should choose Y for yes or N for no, please try again."); } } } break; case '8': var studentToDelete = GetStudent(); if (studentToDelete != null) { Console.WriteLine(string.Format("Are you sure that you want to DELETE the student: {0}? (Y/N) [Y]: ", studentToDelete.ToString())); string value = Console.ReadLine(); if (string.IsNullOrEmpty(value) || value[0].ToString().ToUpper() == "Y") { StudentMapper.Delete(studentToDelete.Id); } else { if (!string.IsNullOrEmpty(value) && !(value[0].ToString().ToUpper() == "Y" || value[0].ToString().ToUpper() == "N")) { ShowContinueMessage("You should choose Y for yes or N for no, please try again."); } } } break; } } else { Console.WriteLine("You must type the respective number from 1 to 9 to pick and option from the menu. Press any key to continue ..."); Console.ReadKey(); } } Console.WriteLine("Thanks for using the Student's console client. Press any key to continue ..."); Console.ReadKey(); }
/// <summary> /// Reads from the user the ID and gets the student to edit/update and allows to save changes if any /// </summary> private static void EditStudent() { var student = GetStudent(); if (student != null) { Console.WriteLine("The current student data is: " + student.ToString()); bool changed = false; StudentType type = StudentType.Kinder; Console.WriteLine("Specify the student type (K)inder, (E)lementary, (H)igh, (U)niversity; introducing the letter enclosed in parenthesis and hitting enter or EMPTY if you want keep original: "); string answer = Console.ReadLine(); if (!string.IsNullOrEmpty(answer)) { answer = answer[0].ToString(); switch (answer) { case "K": break; case "E": type = StudentType.Elementary; break; case "H": type = StudentType.High; break; case "U": type = StudentType.University; break; } if (type != student.Type) { student.Type = type; changed = true; } } string name = string.Empty; Console.WriteLine("Please introduce the student's name or EMPTY if you want keep original: "); name = Console.ReadLine(); if (!string.IsNullOrEmpty(name) && name != student.Name) { student.Name = name; changed = true; } Console.WriteLine("Specify the student gender (M)ale, (F)emale; introducing the letter enclosed in parenthesis and hitting enter or EMPTY if you want keep original: "); string gender = string.Empty; gender = Console.ReadLine(); if (!string.IsNullOrEmpty(gender)) { gender = gender.Trim(); if (gender.Length > 0) { gender = gender[0].ToString().ToUpper(); } if ((gender == "M" || gender == "F") && gender != student.Gender[0].ToString()) { student.Gender = gender == "M" ? "Male" : "Female"; changed = true; } } if (changed) { student.UpdatedOn = DateTime.Now; if (StudentMapper.Update(student)) { ShowContinueMessage("The student was updated successfully."); } else { ShowContinueMessage("We found and error updating the student please review logs and try again."); } } else { ShowContinueMessage("You did not change any data on the student, so there is nothing to save."); } } }
/// <summary> /// Reads valid data to create a new student and save it to the database /// </summary> private static void CreateStudent() { StudentType type = StudentType.Kinder; bool validType = false; Console.WriteLine("Specify the student type (K)inder, (E)lementary, (H)igh, (U)niversity; introducing the letter enclosed in parenthesis and hitting enter: "); string answer = Console.ReadLine(); if (!string.IsNullOrEmpty(answer)) { answer = answer[0].ToString().ToUpper(); switch (answer) { case "K": validType = true; break; case "E": validType = true; type = StudentType.Elementary; break; case "H": validType = true; type = StudentType.High; break; case "U": validType = true; type = StudentType.University; break; } } string name = string.Empty; Console.WriteLine("Please introduce the student's name, it must no be empty: "); name = Console.ReadLine(); Console.WriteLine("Specify the student gender (M)ale, (F)emale; introducing the letter enclosed in parenthesis and hitting enter: "); string gender = string.Empty; gender = Console.ReadLine(); if (!string.IsNullOrEmpty(gender)) { gender = gender.Trim(); if (gender.Length > 0) { gender = gender[0].ToString().ToUpper(); } } if (validType && !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(gender) && (gender == "M" || gender == "F")) { Student student = new Student(); student.Type = type; student.Name = name; student.Gender = gender == "M" ? "Male" : "Female"; student.Enabled = true; student.UpdatedOn = DateTime.Now; if (!StudentMapper.Exists(student)) { if (StudentMapper.Insert(student)) { ShowContinueMessage("The student was added successfully."); } else { ShowContinueMessage("We found and error adding the student please review logs and try again."); } } else { ShowContinueMessage("There is already a student with the same data added, we don't allow duplicates. You can search it for edit if you want."); } } else { ShowContinueMessage("There is an error with your data. Please verify that the Type is K for Kinder, E for Elementary, H for High, U for University, The name is not empty and Gender is M for Male or F for Female."); } }
private async void startVerifyButton_Click(object sender, EventArgs e) { progressBar1.Value = 25; List <FullStudent> students = await GetAllFullStudents(); progressBar1.Value = 50; Console.WriteLine($"Total records: {students.Count}"); string student1 = ""; string student2 = ""; numOfRecords.Text = students.Count.ToString(); // now that we have the fullstudent records, we can start the verfication of them all BasicStudent genesisStudent = StudentMapper.GenesisStudentNode(); // start at the end of the records and then recalculate the hash of the node and check if it matches with the one on record // then recalculate the hash of the previous node and check to see if it matches with the currents previous on record // if both are valid, then the record is considered to be valid // otherwise, the record is invalid // Print some debug info alongside bool valid = true; for (int i = students.Count - 1; i >= 0; i--) { bool currentHashMatch = true; bool previousHashMatch = true; bool previousFullHashMatch = true; FullStudent currentFullStudent = students[i]; Console.WriteLine($"Current Student: {currentFullStudent.FirstName}"); string recalculatedCurrentNodeHash = CalculateCurrentFullStudentHash(currentFullStudent); if (recalculatedCurrentNodeHash != currentFullStudent.CurrentNodeHash) { currentHashMatch = false; } if (i == 0) { Console.WriteLine($"Genesis Node Previous: Test"); string previousGenesisHash = Hash.GetHashString("Test"); if (currentFullStudent.PreviousRecordHash != previousGenesisHash) { previousHashMatch = false; } if (previousGenesisHash != currentFullStudent.PreviousFullRecordHash) { previousFullHashMatch = false; } } else { FullStudent previousFullStudent = students[i - 1]; Console.WriteLine($"Previous Student: {previousFullStudent.FirstName}"); string recalculatedPreviousNodeHash = CalculateCurrentFullStudentHash(previousFullStudent); if (currentFullStudent.PreviousRecordHash != recalculatedPreviousNodeHash) { previousHashMatch = false; student2 = previousFullStudent.FirstName; } // new string previousFullHashObject = JsonConvert.SerializeObject(previousFullStudent); string previousFullHash = Hash.GetHashString(previousFullHashObject); if (previousFullHash != currentFullStudent.PreviousFullRecordHash) { previousFullHashMatch = false; } } if (!currentHashMatch || !previousHashMatch || !previousFullHashMatch) // also check the fullnodehashmatch { valid = false; student1 = currentFullStudent.FirstName; break; } } progressBar1.Value = 100; if (valid) { MessageBox.Show("Hash Verified and Unmodified", "Success"); } else { if (student2.Length == 0) { MessageBox.Show($"Hash mismatch on {student1}", "Error"); } else { MessageBox.Show($"Hash mismatch on {student1} and {student2}", "Error"); } } }
public ActionResult <List <StudentViewModel> > GetAllStudents() { return(Ok(StudentMapper.GetStudentsViewFrom(_studentService.GetAllStudents()))); }
private void MainScreen_Load(object sender, EventArgs e) { panelBlank.Visible = false; panelMult.Visible = false; panelTF.Visible = false; buttonList.Add(button1); buttonList.Add(button2); buttonList.Add(button3); buttonList.Add(button4); buttonList.Add(button5); buttonList.Add(button6); buttonList.Add(button7); buttonList.Add(button8); buttonList.Add(button9); buttonList.Add(button10); buttonList.Add(buttonFinalExam); questionPanelList.Add(panelBlank); questionPanelList.Add(panelMult); questionPanelList.Add(panelTF); if (LoginScreen.userType == "student") //User is a Student { activeStudent = StudentMapper.Get(LoginScreen.activeUser); if (activeStudent.Level < 12) //Update buttons based on quiz completion (Level) { for (int i = 0; i < activeStudent.Level; i++) { buttonList[i].Enabled = true; buttonList[i].Image = Resources.tick; toolTipMain.SetToolTip(buttonList[i], "Έχει ολοκληρωθεί η προπαίδεια του " + (i + 1).ToString()); } buttonList[activeStudent.Level - 1].Image = Resources.unlock; toolTipMain.SetToolTip(buttonList[activeStudent.Level - 1], "Διαβάστε την προπαίδεια και όταν είστε έτοιμοι δοκιμάστε το τεστ!"); buttonList[activeStudent.Level - 1].PerformClick(); } else //Update all buttons as complete { for (int i = 0; i <= 10; i++) { buttonList[i].Enabled = true; buttonList[i].Image = Resources.tick; toolTipMain.SetToolTip(buttonList[i], "Έχει ολοκληρωθεί η προπαίδεια του " + (i + 1).ToString()); } buttonList[10].PerformClick(); } pictureBoxGrades.Visible = true; studentGrades.Add(labelGradeShow1); studentGrades.Add(labelGradeShow2); studentGrades.Add(labelGradeShow3); studentGrades.Add(labelGradeShow4); studentGrades.Add(labelGradeShow5); studentGrades.Add(labelGradeShow6); studentGrades.Add(labelGradeShow7); studentGrades.Add(labelGradeShow8); studentGrades.Add(labelGradeShow9); studentGrades.Add(labelGradeShow10); studentGrades.Add(labelGradeShowFinal); } else //User is a professor { activeProfessor = ProfessorMapper.Get(LoginScreen.activeUser); for (int i = 0; i < 11; i++) { buttonList[i].Visible = false; } buttonSave.Visible = true; panelProf.Visible = true; buttonTakeQuiz.Visible = false; pictureBoxSettings.Enabled = false; labelTitle.Text = "Διαχείριση Μαθητών"; labelTitleNumber.Visible = false; gradesList.Add(numericUpDown1); gradesList.Add(numericUpDown2); gradesList.Add(numericUpDown3); gradesList.Add(numericUpDown4); gradesList.Add(numericUpDown5); gradesList.Add(numericUpDown6); gradesList.Add(numericUpDown7); gradesList.Add(numericUpDown8); gradesList.Add(numericUpDown9); gradesList.Add(numericUpDown10); gradesList.Add(numericUpDownFinal); } }
public ActionResult <List <StudentViewModel> > GetStudentsByCompanyId(int companyId) { var studentsByCompany = _studentService.GetStudentsByInternshipId(companyId); return(Ok(StudentMapper.GetStudentsViewFrom(studentsByCompany))); }
public bool AddStudent(StudentDAO student) { var stud = StudentMapper.MapToStudent(student); return(InsertData.InsertStudent(stud)); }
public bool dropCourseFromStudent(StudentDAO student, CourseDAO course) { return(studentstuff.dropCourse(StudentMapper.MapToStudent(student), CourseMapper.MapToCourse(course))); }
public List<Student> DoRead() { Mapper = new StudentMapper(); return Mapper.GetAll(); }
private void endQuiz() { //hide every question questionPanelList[0].Visible = false; questionPanelList[0].Location = hideBlank; questionPanelList[1].Visible = false; questionPanelList[1].Location = hideMult; questionPanelList[2].Visible = false; questionPanelList[2].Location = hideTF; pictureBoxNext.Visible = false; panelResult.Visible = true; panelResult.Location = questionPoint; //Get results-grade quizManager.GradeQuiz(); grade = quizManager.QuizGrade; //Update UI based on results progressBarResult.Value = grade; labelResultGrade.Text = grade.ToString() + "/100"; if (currentNumber != 0) //Quiz { if (activeStudent.StudentProgress.PropaideiaProgress[currentNumber - 1] < grade) { activeStudent.StudentProgress.PropaideiaProgress[currentNumber - 1] = grade; } if (grade > 80) { buttonList[currentNumber - 1].Image = Resources.tick; toolTipMain.SetToolTip(buttonList[currentNumber - 1], "Έχει ολοκληρωθεί η προπαίδεια του " + currentNumber); if (!buttonList[currentNumber].Enabled) { buttonList[currentNumber].Image = Resources.unlock; toolTipMain.SetToolTip(buttonList[currentNumber], "Διαβάστε την προπαίδεια και όταν είστε έτοιμοι δοκιμάστε το τεστ!"); buttonList[currentNumber].Enabled = true; } labelResult.Text = "Συγχαρητήρια!!!\nΠέρασες το quiz με βαθμό: "; if (activeStudent.Level <= currentNumber) { activeStudent.Level = currentNumber + 1; } } else { labelResult.Text = "Δεν πέρασες το τεστ!\nΔιάβασε ξανά την προπαίδεια\nκαι ξαναδοκίμασε!"; } } else //Final Exam { activeStudent.StudentProgress.FinalExam = grade; if (grade > 80) { buttonList[10].Image = Resources.tick; buttonList[10].Enabled = true; labelResult.Text = "Συγχαρητήρια!!!\nΠέρασες την εξέταση με βαθμό: "; if (activeStudent.Level < 12) { activeStudent.Level = 12; } } } StudentMapper.Update(activeStudent); }
private void LoadRoomsAndStudents(object sender, EventArgs e) { UpdateRoomList(DormRoomMapper.GetAllRooms()); UpdateStudentsFromRoomList(StudentMapper.ReadAllStudents()); UpdateStudentsList(StudentMapper.ReadAllStudents()); }