Beispiel #1
0
        private void AddStudent(Students entityToAdd)
        {
            IStudentsRepository repo = new StudentsRepository(getEntities());

            Entities.Students entityToAdd2 = Mapper.Map <Students, Entities.Students>(entityToAdd);
            repo.Add(entityToAdd2);
        }
        private void CreateEdit(object sender, EventArgs e)
        {
            if (!CheckInputFields())
            {
                return;
            }

            if (_studentToEdit == null)
            {
                var newStudent = new Student
                {
                    FirstName = firstNameTextBox.Text,
                    LastName  = lastNameTextBox.Text,
                    Birthdate = birthdayDatePicker.Value.Date,
                    Class     = classComboBox.SelectedItem.ToString(),
                    Gender    = (maleRadioButton.Checked) ? Gender.Male : Gender.Female
                };

                _studentsRepository.Add(newStudent);
            }
            else
            {
                _studentToEdit.FirstName = firstNameTextBox.Text;
                _studentToEdit.LastName  = lastNameTextBox.Text;
                _studentToEdit.Birthdate = birthdayDatePicker.Value.Date;
                _studentToEdit.Gender    = (maleRadioButton.Checked) ? Gender.Male : Gender.Female;
                _studentToEdit.Class     = classComboBox.SelectedItem.ToString();

                _studentsRepository.Edit(_studentToEdit);
            }

            Close();
        }
Beispiel #3
0
        // POST api/Students
        public IHttpActionResult Post([FromBody] Student value)
        {
            var student = new Student
            {
                FirstName = value.FirstName,
                LastName  = value.LastName
            };

            studentsRepository.Add(student);
            data.SaveChanges();
            return(this.StatusCode(HttpStatusCode.Created));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "id,RegistrationID,FirstName,SecondName,Email,PhoneNumber")] Student student)
        {
            if (ModelState.IsValid)
            {
                // db.Students.Add(student);
                //db.SaveChanges();
                db.Add(student);
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
        public ActionResult Create([Bind(Include = "StudentId,FirstName,LastName,CNP,Specialization,YearOfStudy")] StudentVM studentVM)
        {
            if (ModelState.IsValid)
            {
                Student student = StudentMap.StudentVMToStudent(studentVM);

                studentRepo.Add(student);

                return(RedirectToAction("Index"));
            }

            return(View(studentVM));
        }
Beispiel #6
0
        public void AddUser(Users entityToAdd)
        {
            IUsersRepository repo = new UsersRepository(getEntities());

            Entities.Users entityToAdd2 = Mapper.Map <Users, Entities.Users>(entityToAdd);
            repo.Add(entityToAdd2);
            switch (entityToAdd.UserType.ToUpper())
            {
            case "ADMINISTRATOR":
                IAdministratorsRepository adminRepo = new AdministratorsRepository(getEntities());
                Entities.Administrators   admin     = new Entities.Administrators()
                {
                    UserId = entityToAdd.Id
                };
                adminRepo.Add(admin);
                break;

            case "MANAGER":
                IManagersRepository managerRepo = new ManagersRepository(getEntities());
                Entities.Managers   manager     = new Entities.Managers()
                {
                    UserId = entityToAdd.Id
                };
                managerRepo.Add(manager);
                break;

            case "STUDENT":
                IStudentsRepository studentRepo = new StudentsRepository(getEntities());
                Entities.Students   student     = new Entities.Students()
                {
                    UserId = entityToAdd.Id
                };
                studentRepo.Add(student);
                break;

            case "TEACHER":
                ITeachersRepository teacherRepo = new TeachersRepository(getEntities());
                Entities.Teachers   teacher     = new Entities.Teachers()
                {
                    UserId = entityToAdd.Id
                };
                teacherRepo.Add(teacher);
                break;

            default:; break;
            }
        }
Beispiel #7
0
        public void Post()
        {
            // Arrange
            var repository = new StudentsRepository(new StudentsEntities());

            // Act
            Student newStudent = new Student()
            {
                firstName = "kiro",
                lastName = "ivanov",
                age = 20,
                grade = 7
            };

            repository.Add(newStudent);

            // Assert
            var count = repository.All().Count();
            Assert.AreEqual(3, count);
        }