public void AddStudent(StudentPostModel newPostStModel) { if ((newPostStModel.Age <= 0) || (newPostStModel.Payments == null)) { Console.WriteLine("Input error"); return; } var service = new StudentService(); List <PaymentModel> mappedPayments = new List <PaymentModel>(); foreach (var item in newPostStModel.Payments) { mappedPayments.Add(new PaymentModel() { Date = item.Date, Value = item.Value }); } StudentModel studModelToAdd = new StudentModel() { FirstName = newPostStModel.FirstName, Lastname = newPostStModel.Lastname, Age = newPostStModel.Age, Payments = mappedPayments }; service.AddStudent(studModelToAdd); }
public ActionResult StudentRegistration(Student student) { StudentService studentService = new StudentService(); studentService.AddStudent(student); return(RedirectToAction("Index", "Admin", new { area = "" })); }
public ActionResult Create(CreateStudentView FormData) { try { //if(String.IsNullOrEmpty(FormData.FirstName)) //{ // ViewData["FirstNameError"] = " First name must be not null"; // return View(); //} if (!ModelState.IsValid) { return(View()); } StudentService studentService = new StudentService(); List <Student> studentList = studentService.GetStudents(); Student student = Mapper.Map <Student>(FormData); student.Uuid = Guid.NewGuid(); student.LastLogin = null; student.CreatedAt = DateTime.Now; student.UpdatedAt = DateTime.Now; studentService.AddStudent(student); return(RedirectToAction("Index")); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); return(View()); } }
public void Execute() { try { Console.WriteLine("\nPlease give student's Id - Integer: "); var id = int.Parse(Console.ReadLine()); Console.WriteLine("\nPlease give student's name - string: "); var name = Console.ReadLine(); Console.WriteLine("\nPlease give student's group - Integer: "); var @group = int.Parse(Console.ReadLine()); Console.WriteLine("\nPlease give student's email - String: "); var email = Console.ReadLine(); var retValue = _srv.AddStudent(id, name, group, email); Console.WriteLine(retValue == null ? "The student was added successfully!\n" : "The student is already in the repository!\n"); } catch (ValidatorException e) { Console.WriteLine("\n" + e.Message + "\n"); } catch (FormatException e) { Console.WriteLine("\n" + e.Message + "\n"); } }
public ActionResult Create(CreateStudentView FormData) { try { if (!ModelState.IsValid) { return(View(FormData)); } StudentService studentService = new StudentService(); List <Student> studentList = studentService.GetStudents(); Student student = Mapper.Map <Student>(FormData); student.Uuid = Guid.NewGuid(); student.LastLogin = null; student.CreatedAt = DateTime.Now; student.UpdatedAt = DateTime.Now; studentService.AddStudent(student); return(RedirectToAction("Index")); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); return(View()); } }
public void InsertStudent() { //svc.InitializeData(); ICollection <Student> students = svc.GetStudents(); int beforeCount = students.Count; Student oldStudent = students.FirstOrDefault(x => x.LastName == "O'Donnell" && x.FirstName == "Danny"); if (oldStudent != null) { svc.DeleteStudent(oldStudent.Id); ResetUnitOfWork(); } string firstName = "Danny"; string lastName = "O'Donnell"; string gender = "M"; int graduationYear = 1982; int mathGeniusId = 9991; svc.AddStudent(mathGeniusId, firstName, lastName, gender, graduationYear); ResetUnitOfWork(); students = svc.GetStudents(); int afterCount = students.Count; Assert.IsTrue(afterCount == beforeCount); }
public ActionResult Register(StudentViewModel student) { if (student.Email.IsValidEmailAddress()) { try { StudentService regViewModel = new StudentService(); regViewModel.AddStudent(student); } catch (Exception ex) { ViewBag.Error = ex.Message; return(View("Register", student)); } return(View("Register3", student)); } else { TeacherService ts = new TeacherService(); List <TeacherViewModel> listTeacher = new List <TeacherViewModel>(); listTeacher = ts.GetTeachers(); ViewBag.Teachers = listTeacher; ModelState.AddModelError("", ""); return(PartialView("_register")); } }
public async Task AddStudent_PersistsStudent() { var student = new Student { FirstName = "John", LastName = "Doe", SectionId = 1 }; using (var context = new ApplicationDbContext(Options)) { var service = new StudentService(context); Student addedStudent = await service.AddStudent(student); Assert.AreEqual(addedStudent, student); Assert.AreNotEqual(0, addedStudent.Id); } using (var context = new ApplicationDbContext(Options)) { Student retrievedStudent = context.Students.Single(); Assert.AreEqual(student.FirstName, retrievedStudent.FirstName); Assert.AreEqual(student.LastName, retrievedStudent.LastName); } }
public JsonResult AddStudent(int?MathGeniusId, string LastName, string FirstName, string Sex, int?GraduationYear) { string sex = Sex == "Male" ? "M" : "F"; ServiceResult result = _studentService.AddStudent(MathGeniusId, LastName, FirstName, sex, GraduationYear); return(Json(FinalizeResult(result), JsonRequestBehavior.AllowGet)); }
public IActionResult CreateStudentNew([FromBody] Students student) { try { var AddedStudent = StudentService.AddStudent(student); ResponseDTO response = new ResponseDTO(); if (AddedStudent != null) { response.StatusCode = "Success"; response.Message = "Successfully Created"; response.Data = AddedStudent; return(Ok(response)); } else { response.StatusCode = "Warning"; response.Message = "Invalid request."; response.Data = null; return(BadRequest(response)); } } catch (Exception ex) { ResponseDTO Failure = new ResponseDTO(); Failure.StatusCode = "Failed"; Failure.Message = ex.Message; Failure.Data = null; return(BadRequest(Failure)); } }
public async Task <IActionResult> RegisterStudentAsync([FromForm] RegisterStudentViewModel studentView) { var student = StudentMapper.ToActualObjectNoId(studentView); RegisterViewModel registration = new RegisterViewModel { Email = studentView.Email, Password = studentView.Password, ConfirmPassword = studentView.ConfirmPassword }; IdentityResult result = await _userManager.CreateAsync(new ApplicationUser { Email = registration.Email, UserName = registration.Email }, registration.Password); if (result.Succeeded) { var studentUserManager = await _userManager.FindByEmailAsync(registration.Email); var roleStudent = await _roleManager.FindByNameAsync("Student"); await _userManager.AddToRoleAsync(studentUserManager, roleStudent.Name); student.IdUser = studentUserManager.Id; _studentService.AddStudent(student); if (studentView.Cv != null) { _studentService.UploadCV(student.IdUser, studentView.Cv); } return(Ok()); } return(BadRequest()); }
public ActionResult StudentRegistration(StudentMaster student) { StudentService add = new StudentService(); add.AddStudent(student); return(RedirectToAction("AllStudents")); }
public void ShouldAddNewStudent() { var context = CreateDbContext(); var service = new StudentService(context.Object); var result = service.AddStudent(testStudent); Assert.Equal(1, result); }
protected async Task AddStudent() { if (Model.StudentName != "" && Model.Class_ID > 0) { await StudentService.AddStudent(Model); } _Student = await StudentService.GetStudents_API(); }
public void Add(object o) { Student s = new Student(); s.ID = this.ID; s.Name = this.Name; s.Age = this.Age; studentService.AddStudent(s); }
public void Add(object sender, EventArgs e) { Student student = new Student(nameTxt.Text, int.Parse(ageTxt.Text), locationTxt.Text); studentList.Add(student); studentService.AddStudent(studentList); nameTxt.Text = ""; ageTxt.Text = ""; locationTxt.Text = ""; }
public ActionResult Create([Bind(Include = "Id,name,age,luckyNumber")] Student student) { if (ModelState.IsValid) { service.AddStudent(student); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Create(Student student) { if (ModelState.IsValid) { service.AddStudent(student); return(RedirectToAction("Index")); } return(View(student)); }
private void addButton_Click(object sender, EventArgs e) { Student student = new Student(nameTextbox.Text, int.Parse(ageTextbox.Text), addressTextBox.Text); studentList.Add(student); studentService.AddStudent(studentList); nameTextbox.Text = ""; ageTextbox.Text = ""; addressTextBox.Text = ""; }
public void AddStudent_StudentIsNull_ExpectArgumentException() { // arrange var service = new StudentService(repoMock.Object); // act + assert var ex = Assert.Throws <ArgumentException>(() => service.AddStudent(null)); Assert.Equal("Student is missing", ex.Message); repoMock.Verify(repo => repo.Add(It.Is <Student>(s => s == null)), Times.Never); }
public IActionResult Create(StudentDto s) { if (ModelState.IsValid) { var Student = _service.AddStudent(s.Name, s.Email, s.Course, s.Age, s.Grade); if (Student != null) { return(CreatedAtAction(nameof(Get), new { Id = Student.Id }, Student)); } } return(BadRequest(ModelState)); }//Create
public bool Add(StudentViewModel studentViewModel) { try { studentService.AddStudent(studentViewModel); return(true); } catch (Exception ex) { throw; } }
public IHttpActionResult PostAddStudent(Student student) { if (student == null) { return(InternalServerError()); } else { _service.AddStudent(student); return(Ok("Data Added.")); } }
public IActionResult Create([Bind("Name,Course,Age,Email")] StudentViewModel vm) { if (ModelState.IsValid) { // add student via service var s = svc.AddStudent(vm.ToStudent()); Alert("Student created successfully", AlertType.success); return(RedirectToAction(nameof(Details), new { Id = s.Id })); } // redisplay the form for editing return(View(vm)); }
public IActionResult Create([Bind("Name, Email, Course, Age")] Student s) { // verify the model s is valid (passes validation rules defined on Student) if (ModelState.IsValid) { svc.AddStudent(s.Name, s.Email, s.Course, s.Age, 0); Alert("Student created successfully", AlertType.success); return(RedirectToAction(nameof(Index))); } // redisplay the form for editing as there are validation errors return(View(s)); }
public void AddAlreadyExistStudent() { // Arrange dynamic TestObj = new JObject(); TestObj.Name = "Óttar Helgi Einarsson"; TestObj.SSN = MockFactory.SSN_OTTAR; TestObj.DepartmentID = "1"; TestObj.Major = new JObject(); TestObj.Major.ID = MockFactory.MAJOR_ID_BSC_COMP_SCI; TestObj.Major.Name = "Meistaranám í tölvunarfræði"; // Act: var oldList = _mockFactory.GetMockData <Student>().Count; // list should not change since student already exists _service.AddStudent(TestObj); var newList = _mockFactory.GetMockData <Student>().Count; // Assert: Assert.AreEqual(oldList, newList); }
public async Task <JsonResult> AddStudent(string name, string lastName, string fatherName, DateTime dateOfBirth, DateTime trialDate, DateTime startDate, string parentName, string parentLastName, string parentFatherName, string phoneNumber, int status, int levelId, string text, int groupId) { if (!string.IsNullOrWhiteSpace(phoneNumber)) { await _studentService.AddStudent(name, lastName, fatherName, dateOfBirth, trialDate, startDate, parentName, parentLastName, parentFatherName, phoneNumber, status, levelId, text, groupId); return(new JsonResult(StatusCode(200))); } Response.StatusCode = 500; return(new JsonResult("Укажите номер телефона")); }
public IActionResult Create(Student s) { // Q2c - complete POST action to add student // if model is valid if (ModelState.IsValid) { // pass data to service to store var saved = svc.AddStudent(s.Name, s.Email, s.Course, s.Age, s.Profile.Grade); // Redirect to index URL return(RedirectToAction(nameof(Details), new { Id = saved.Id })); // end } // redisplay the form for editing as there are validation errors return(View(s)); }
public ServiceResult AddStudentTest( [PexAssumeUnderTest] StudentService target, int?mathGeniusId, string lastName, string firstName, string gender, int?graduationYear ) { ServiceResult result = target.AddStudent(mathGeniusId, lastName, firstName, gender, graduationYear); return(result); // TODO: add assertions to method StudentServiceTest.AddStudentTest(StudentService, Nullable`1<Int32>, String, String, String, Nullable`1<Int32>) }
private void Button_Click(object sender, RoutedEventArgs e) { bool? isReg = IsRegistered.IsChecked; int Id = Int32.Parse(txtId.Text); string first = txtFirstName.Text; string last = txtLastName.Text; Student s = new Student(Id, first, last, isReg); ss.AddStudent(s); ls.Add(s); MessageBox.Show(Int32.Parse(txtId.Text) + "\n" + txtFirstName.Text + "\n" + txtLastName.Text + "\n" + isReg); }
private void SaveStudentDataToWebService() { // start web service StudentService service = new StudentService(); Student newStudent = new Student { Id = TextBox_StudentId.Text, Email = TextBox_Email.Text, Name= TextBox_StudentName.Text }; Student student = service.AddStudent(newStudent); if (student != null) Response.Write("Success"); else Response.Write("fail"); }