public JsonResult Add(StudentViewModel viewModel) { // Populate VM viewModel = PopulateViewModel(viewModel); // Validate model state if (!ModelState.IsValid) return Json(new { error = true, message = "There were errors in the submission" }); // Attempt to add the student to the database/course offering try { // Get the created student from the factory var studentFactory = new StudentFactory(); var student = studentFactory.CreateStudent(viewModel.Number.ToString(), viewModel.Name, viewModel.Type); // Get the course offering var offering = _courseService.GetCourseOffering(viewModel.SelectedYear, viewModel.SelectedSemester, viewModel.SelectedOffering); // Add the student _courseService.AddStudent(student, offering); } catch (StudentExistsException) { return Json(new { error = true, message = "Student already in course offering" }); } return Json(new { error = false, message = "Student successfully added to course offering!" }); }
static void Main(string[] args) { int studentsCount = int.Parse(Console.ReadLine()); StudentFactory studentFactory = new StudentFactory(); List <Student> students = new List <Student>(); for (int counter = 0; counter < studentsCount; counter++) { string[] studentArgs = Console.ReadLine() .Split() .ToArray(); Student student = studentFactory.CreateStudent(studentArgs); students.Add(student); } foreach (var student in students .Where(x => x.Average >= 5) .OrderBy(x => x.Name) .ThenByDescending(x => x.Average)) { Console.WriteLine(student); } }
private static Human Parse(string humanInfo) { var arr = humanInfo.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 3) { return(StudentFactory.CreateStudent(arr)); } return(WorkerFactory.CreateWorker(arr)); }
public void CanMapProperty() { Assert.DoesNotThrow(() => { Student writer = new Student(); propertyMapper.Map <Student>(StudentFactory.CreateDataRow(StudentFactory.CreateStudent()), writer); Assert.NotNull(writer.FirstName, "The FirstName property must not be null"); Assert.NotNull(writer.LastName, "The LastName property must not be null"); }, "The map operation must be successful"); }