public Student AddStudent(Student student) { student.StudentId = _dataSource.Students.Count > 0 ? (_dataSource.Students[_dataSource.Students.Count - 1].StudentId + 1) : 1; _dataSource.Students.Add(student); return student; }
public static object CreateStudent(Student record) { try { var addedStudent = _repository.StudentRepository.AddStudent(record); return new { Result = "OK", Record = addedStudent }; } catch (Exception ex) { return new { Result = "ERROR", Message = ex.Message }; } }
public JsonResult CreateStudent(Student student) { try { if (!ModelState.IsValid) { return Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." }); } var addedStudent = _repository.StudentRepository.AddStudent(student); return Json(new { Result = "OK", Record = addedStudent }); } catch (Exception ex) { return Json(new { Result = "ERROR", Message = ex.Message }); } }
private void AddPhonesToStudent(MemoryDataSource dataSource, Student student) { var phoneCount = _rnd.Next(2, 7); for (var j = 0; j < phoneCount; j++) { var phoneId = dataSource.Phones.Count > 0 ? dataSource.Phones[dataSource.Phones.Count - 1].PhoneId + 1 : 1; dataSource.Phones.Add(new Phone { PhoneId = phoneId, StudentId = student.StudentId, Number = GenerateRandomPhoneNumber(), PhoneType = _rnd.Next(1, 4) }); } }
private void AddExamsToStudent(MemoryDataSource dataSource, Student student, string[] courseNames, string[] examDegrees) { var examCount = _rnd.Next(4, 10); for (var j = 0; j < examCount; j++) { var studentExamId = dataSource.StudentExams.Count > 0 ? dataSource.StudentExams[dataSource.StudentExams.Count - 1].StudentExamId + 1 : 1; dataSource.StudentExams.Add( new StudentExam { StudentExamId = studentExamId, StudentId = student.StudentId, CourseName = courseNames[_rnd.Next(courseNames.Length)], Degree = examDegrees[_rnd.Next(examDegrees.Length)], ExamDate = new DateTime(_rnd.Next(2008, 2012), _rnd.Next(1, 13), _rnd.Next(1, 29)) }); } }
public MemoryDataSource Generate(int studentCount) { var dataSource = new MemoryDataSource(); //BASE DATA var personNames = GeneratePersonNames(); var courseNames = GenerateCourseNames(); var examDegrees = GenerateExamDegrees(); //CITIES dataSource.Cities.AddRange( new[] { new City {CityId = 1, CityName = "Adana"}, new City {CityId = 2, CityName = "Ankara"}, new City {CityId = 3, CityName = "Athens"}, new City {CityId = 4, CityName = "Beijing"}, new City {CityId = 5, CityName = "Berlin"}, new City {CityId = 6, CityName = "Bursa"}, new City {CityId = 7, CityName = "İstanbul"}, new City {CityId = 8, CityName = "London"}, new City {CityId = 9, CityName = "Madrid"}, new City {CityId = 10, CityName = "Mekke"}, new City {CityId = 11, CityName = "New York"}, new City {CityId = 12, CityName = "Paris"}, new City {CityId = 13, CityName = "Samsun"}, new City {CityId = 14, CityName = "Trabzon"}, new City {CityId = 15, CityName = "Volos"} }); //STUDENTS for (int i = 0; i < studentCount; i++) { var nameIndex = _rnd.Next(personNames.Length); var surnameIndex = _rnd.Next(personNames.Length); var student = new Student { Name = personNames[nameIndex].Name + " " + personNames[surnameIndex].Surname, EmailAddress = personNames[nameIndex].Name.ToLower() + "." + personNames[surnameIndex].Surname.ToLower() + "@jtable.org", Gender = personNames[nameIndex].Gender, CityId = dataSource.Cities[_rnd.Next(dataSource.Cities.Count)].CityId, BirthDate = new DateTime(_rnd.Next(1940, 2005), _rnd.Next(1, 13), _rnd.Next(1, 29)), StudentId = (i + 1), IsActive = (_rnd.Next(100) > 20), Education = _rnd.Next(1, 4) }; dataSource.Students.Add(student); //PHONES AddPhonesToStudent(dataSource, student); //EXAMS AddExamsToStudent(dataSource, student, courseNames, examDegrees); } //PEOPLE dataSource.People.AddRange( new List<Person> { new Person {PersonId = 1, Name = "George Orwell", Age = 27}, new Person {PersonId = 2, Name = "Douglas Adams", Age = 42}, new Person {PersonId = 3, Name = "Isaac Asimov", Age = 26}, new Person {PersonId = 3, Name = "Dan Brown", Age = 39}, new Person {PersonId = 4, Name = "Thomas More", Age = 65} }); return dataSource; }
public static object UpdateStudent(Student record) { return DemoMethods.UpdateStudent(record); }
public void UpdateStudent(Student student) { var foundStudent = _dataSource.Students.FirstOrDefault(s => s.StudentId == student.StudentId); if (foundStudent == null) { return; } foundStudent.Name = student.Name; foundStudent.EmailAddress = student.EmailAddress; foundStudent.Password = student.Password; foundStudent.Gender = student.Gender; foundStudent.BirthDate = student.BirthDate; foundStudent.CityId = student.CityId; foundStudent.About = student.About; foundStudent.Education = student.Education; foundStudent.IsActive = student.IsActive; }
public static object UpdateStudent(Student record) { try { _repository.StudentRepository.UpdateStudent(record); return new { Result = "OK" }; } catch (Exception ex) { return new { Result = "ERROR", Message = ex.Message }; } }