// GET: Attendence public ActionResult Index() { var db = new StudentContainer(); var batch = db.Batches.ToList(); return(View(batch)); }
public ActionResult Search(string drop) { var db = new StudentContainer(); var students = db.Students.Where(b => b.Batch.Name.ToLower().Contains(drop.ToLower())); return(PartialView(students)); }
public Alumno GetAlumnoById(int id) { var sql = "usp_GetAlumnoByID @id"; var alumno = StudentContainer.Resolve(); using (SqlConnection _conn = new SqlConnection(connectionString)) { using (SqlCommand _cmd = new SqlCommand(sql, _conn)) { _conn.Open(); _cmd.Parameters.AddWithValue("@id", id); SqlDataReader reader = _cmd.ExecuteReader(); while (reader.Read()) { alumno.Id = reader.GetInt32(0); alumno.Dni = reader.GetString(1); alumno.Nombre = reader.GetString(2); alumno.Apellidos = reader.GetString(3); alumno.Edad = reader.GetInt32(4); alumno.Nacimiento = reader.GetDateTime(5); alumno.Registro = reader.GetDateTime(6); alumno.Guid = reader.GetGuid(7); } } } return(alumno); }
public List <Alumno> GetAlumnos() { List <Alumno> alumnos = new List <Alumno>(); var sql = "usp_GetAllAlumnos"; using (SqlConnection _conn = new SqlConnection(connectionString)) { using (SqlCommand _cmd = new SqlCommand(sql, _conn)) { _conn.Open(); SqlDataReader reader = _cmd.ExecuteReader(); while (reader.Read()) { var alumno = StudentContainer.Resolve(); alumno.Id = reader.GetInt32(0); alumno.Dni = reader.GetString(1); alumno.Nombre = reader.GetString(2); alumno.Apellidos = reader.GetString(3); alumno.Edad = reader.GetInt32(4); alumno.Nacimiento = reader.GetDateTime(5); alumno.Registro = reader.GetDateTime(6); alumno.Guid = reader.GetGuid(7); alumnos.Add(alumno); } return(alumnos); } } }
private static void Enlist() { bool wrongInput = false; string firstNameInput; string lastNameInput; string gpaInput; float gpa; Console.WriteLine(); Console.WriteLine("Student:"); firstNameInput = GetUserInput("First name............................: "); lastNameInput = GetUserInput("Last name.............................: "); do { if (wrongInput) { Console.WriteLine("Input number from 1,00 - 5,00 ..."); wrongInput = true; } gpaInput = GetUserInput("GPA...................................: "); } while (!(float.TryParse(gpaInput, out gpa) && gpa >= 1.00 && gpa <= 5.00)); // add student... StudentContainer.AddStudent(new Student(firstNameInput, lastNameInput, float.Parse(gpaInput))); }
static void enlistStudent() { string firstName; string lastName; string gpa; float fGpa; string response; Console.Write("Student"); do { Console.Write("\n" + "First name: "); firstName = Console.ReadLine(); response = Validation.getInstance().validateStrings(firstName); if (!response.Equals(Operations.validationOK)) { Console.Write(response); continue; } }while (!response.Equals(Operations.validationOK)); do { Console.Write("Last name: "); lastName = Console.ReadLine(); response = Validation.getInstance().validateStrings(lastName); if (!response.Equals(Operations.validationOK)) { Console.Write(response + "\n"); continue; } }while (!response.Equals(Operations.validationOK)); do { Console.Write("GPA: "); gpa = Console.ReadLine(); response = Validation.getInstance().validateGpa(gpa); if (!response.Equals(Operations.validationOK)) { Console.Write(response + "\n"); continue; } }while (!response.Equals(Operations.validationOK)); float.TryParse(gpa, out fGpa); Student student = new Student(); student.firstName = firstName; student.lastName = lastName; student.gpa = fGpa; student.id = StudentIdGenerator.getInstance().generateStudentId(); StudentContainer.getInstance().enlistStudent(student); }
static void displayStudents() { int counter = 0; List <Student> studentList = StudentContainer.getInstance().getList(); if (!studentList.Any()) { Console.Write("No students enlisted.\n"); return; } Console.Write("Students in a system:"); foreach (Student student in studentList) { Console.Write("\n" + ++counter + ". " + student.lastName + ", " + student.firstName + " - " + student.gpa + "\n"); } }
public bool DeleteAlumnoById(int id) { var sql = " usp_DeleteAlumnoByID @id"; var alumno = StudentContainer.Resolve(); using (SqlConnection _conn = new SqlConnection(connectionString)) { using (SqlCommand _cmd = new SqlCommand(sql, _conn)) { _conn.Open(); _cmd.Parameters.AddWithValue("@id", id); _cmd.ExecuteNonQuery(); } } bool IsDelete = GetAlumnoById(id).Id == 0; return(IsDelete); }
public static void Main(string[] args) { StudentContainer student = StudentContainer.Instance(); //deklaracija studenta string firstName; string lastName; string gpa; string operation; bool validateOperation; bool validateString; bool result; do { do { Console.WriteLine("Please, type in your prefered operation"); Console.WriteLine("Your operation is: "); operation = Console.ReadLine().ToUpper(); //enforce case-insensitive operation validateOperation = Validation.ValidateOperation(operation); if (validateOperation) { Console.WriteLine("Operation is not recognized"); } else { break; } } while (true); if (operation == Operations.Enlist) { Console.WriteLine("Enlist new student"); do { Console.Write("Student's first name is: "); firstName = Console.ReadLine(); //sprema vrijednost u varijablu firstName validateString = Validation.ValidateString(firstName); //validacija provjerava firstName vrijednost if (validateString) { Console.WriteLine("You need to insert value"); } else { break; //ako je u redu ide na sljedeći unos } } while (true); //ponavlja se unos dok se ne upiše nešto do { Console.Write("Student's last name is: "); lastName = Console.ReadLine(); validateString = Validation.ValidateString(lastName); if (validateString) { Console.WriteLine("You need to insert value"); } else { break; } } while (true); do { Console.Write("Student's GPA is: "); gpa = Console.ReadLine(); result = Validation.ValidateGpa(gpa); if (string.IsNullOrEmpty(gpa)) { Console.WriteLine("You need to insert value"); } else if (!result) { Console.WriteLine("You need to insert numerical value"); } else { break; } } while (true); student.AddStudent(firstName, lastName, gpa); } else { break; } } while (true); if (operation == Operations.Display) { Console.WriteLine("Enlisted students"); if (student.GetStudents().Count < 1) { Console.WriteLine("There are no enlisted students"); } else { foreach (Student st in student.GetStudents()) { Console.WriteLine("{0}. {1}, {2}, {3}", st.Id, st.LastName, st.FirstName, st.Gpa); } } } Console.ReadKey(); }
static void Main(string[] args) { bool x = true; Console.Write("You can enlist students with the 'Enlist' command or display the students you enlisted so far with the 'display' command.\n"); while (x) { Console.Write("Enter your command: "); string operation = Console.ReadLine(); bool gpaEntry = true; switch (Validation.TestOperation(operation)) { case 0: Console.Write("You did not enter an applicable command, try again.\n"); break; case 1: Student newStudent = new Student(); //temporary storage for new students string testGpa; //before moving to StudentContainer? Console.Write("First name: "); while (true) { string testName = Console.ReadLine(); if (Validation.TestName(testName)) { newStudent.FirstName = testName; break; } else { Console.Write("The name has to be at least 2 characters long.\n"); } } while (true) { Console.Write("Last name: "); string testName = Console.ReadLine(); if (Validation.TestName(testName)) { newStudent.LastName = testName; break; } else { Console.Write("The name has to be at least 2 characters long.\n"); } } while (gpaEntry) { Console.Write("GPA: "); testGpa = Console.ReadLine(); switch (Validation.TestGpa(testGpa)) { case 0: gpaEntry = false; newStudent.Gpa = float.Parse(testGpa, System.Globalization.CultureInfo.InvariantCulture); break; case 1: Console.Write("Not a valid number. GPA's range from 0 to 4.\n"); break; case 2: Console.Write("Please only enter a number.\n"); break; } } Console.Write("Student " + newStudent.FirstName + ' ' + newStudent.LastName + " enlisted with ID: " + newStudent.Id + "\n"); if (Validation.TestStudent(newStudent)) { StudentContainer.AddStudent(newStudent); } else { Console.Write("An error occured, no values for student information were registered."); } break; case 2: int i = 1; if (Validation.TestDisplay()) { StudentContainer.SortStudents(); foreach (Student student in StudentContainer.Students) { Console.Write(i + ". " + student.LastName + ", " + student.FirstName + " - " + student.Gpa + "\n"); i++; } x = false; } else { Console.Write("There are no students to display, enlist some using the 'enlist' command.\n"); } break; } } Console.Write("Hit the Esc key to exit."); do { }while (Console.ReadKey(true).Key != ConsoleKey.Escape); }
static void Main(string[] args) { string operation; string firstname; string lastname; string gpa; bool isValid; do { do { Console.Write("Operation:"); operation = Console.ReadLine(); if (!Validation.ValidateOperation(operation)) { isValid = false; Console.WriteLine("This operation does not exist"); } else { isValid = true; } } while (!isValid); if (operation.Equals(Operations.enlist, StringComparison.OrdinalIgnoreCase)) { do { Console.WriteLine("Student"); Console.Write("Firstname:"); firstname = Console.ReadLine(); if (!Validation.ValidateString(firstname)) { isValid = false; Console.WriteLine("You need to insert value"); } else { isValid = true; } } while (!isValid); do { Console.Write("Lastname:"); lastname = Console.ReadLine(); if (!Validation.ValidateString(lastname)) { isValid = false; Console.WriteLine("You need to insert value"); } else { isValid = true; } } while (!isValid); do { float result; Console.Write("GPA:"); gpa = Console.ReadLine(); if (String.IsNullOrEmpty(gpa)) { isValid = false; Console.WriteLine("You need to insert value"); } else if (!float.TryParse(gpa, out result) && !String.IsNullOrEmpty(gpa)) { isValid = false; Console.WriteLine("You need to insert numerical value"); } else { isValid = true; } } while (!isValid); //inserting student into list StudentContainer.InsertStudent(firstname, lastname, gpa); } else { //displaying all students int i = 1; Console.WriteLine("Students in a system:"); foreach (Student s in StudentContainer.GetStudents()) { Console.WriteLine("{0}.{1},{2} - {3}", i, s.LastName, s.Name, s.GPA.Replace(',', '.')); i++; } Console.ReadLine(); } } while (!operation.Equals(Operations.display, StringComparison.OrdinalIgnoreCase)); }