Ejemplo n.º 1
0
        public void UpdateTeacher()
        {
            //Arrange
            var contexFactory = Substitute.For <IContextFactory>();
            var teacherDal    = new TeacherDal(contexFactory);
            var context       = Substitute.For <SchoolContext>();
            var teacherDbSet  = Substitute.For <DbSet <Teacher> >();

            contexFactory.Create().Returns(context);
            context.Teachers = teacherDbSet;

            var teacherDto = new TeacherDto()
            {
                Name    = "Jacek",
                Surname = "Maslak"
            };

            teacherDbSet.Attach(Arg.Do <Teacher>(t =>
                                                 t.Person = new Person()
            {
                Name    = "Pawel",
                Surname = "Styrna"
            }
                                                 ));

            //Act
            teacherDal.UpdateTeacher(1, teacherDto);

            //Assert
            teacherDbSet.Received().Attach(Arg.Is <Teacher>(t => t.Id == 1));
            context.ChangeTracker.Entries().Equals(teacherDto);
            context.Received().SaveChanges();
        }
Ejemplo n.º 2
0
        public void CreateTeacher()
        {
            //Arrange
            var contexFactory = Substitute.For <IContextFactory>();
            var context       = Substitute.For <SchoolContext>();
            var teacherDbSet  = Substitute.For <DbSet <Teacher> >();

            var teacherDal = new TeacherDal(contexFactory);
            var teacherDto = new TeacherDto()
            {
                Name    = "Jacek",
                Surname = "Maslak"
            };

            contexFactory.Create().Returns(context);
            context.Teachers = teacherDbSet;

            teacherDbSet.Add(Arg.Do <Teacher>(t => t.Id = 1));

            //Act
            var id = teacherDal.CreateTeacher(teacherDto).Result;

            //Assert
            teacherDbSet.Received().Add(Arg.Is <Teacher>(
                                            t => t.Person.Name == teacherDto.Name &&
                                            t.Person.Surname == teacherDto.Surname));
            context.Received().SaveChangesAsync();
            Assert.That(id, Is.EqualTo(1));
        }
        public Object validateTeacher(TeacherDto teacherDto)
        {
            BaseResponseDto <UserAuthDto> baseResponseDto = new BaseResponseDto <UserAuthDto>();
            Notification notification = new Notification();

            Teacher autTheacher = null;

            autTheacher = this.teacherRepository.GetByDni(teacherDto.Dni, teacherDto.SchoolID);

            if (autTheacher.Dni == null)
            {
                notification.addError("El DNI: " + teacherDto.Dni + " no existe o aún no está registrado");
                return(this.getApplicationErrorResponse(notification.getErrors()));
            }

            if (!Hashing.CheckMatch(autTheacher.password, teacherDto.Password))
            {
                notification.addError("La contraseña es incorrecta");
                return(this.getApplicationErrorResponse(notification.getErrors()));
            }

            UserAuthDto userAuthDto = null;

            userAuthDto = this.buildUserAuthDto(autTheacher);

            List <UserAuthDto> usersAuthDto = new List <UserAuthDto>();

            usersAuthDto.Add(userAuthDto);

            baseResponseDto.Data = usersAuthDto;
            return(baseResponseDto);
        }
Ejemplo n.º 4
0
        public IHttpActionResult Create(TeacherDto dto)
        {
            var teacherId = !db.Teachers.Any() ? 1 : db.Teachers.Max(t => t.ID) + 1;
            var teacher   = new Teacher()
            {
                ID        = teacherId,
                Name      = dto.Name,
                BirthDate = dto.BirthDate
            };

            var studentTeachers = new List <StudentTeacher>();

            foreach (var studentId in dto.StudentIds)
            {
                studentTeachers.Add(new StudentTeacher()
                {
                    TeacherId = teacherId,
                    StudentId = studentId
                });
            }
            db.Teachers.Add(teacher);
            db.StudentTeachers.AddRange(studentTeachers);

            db.SaveChanges();
            return(Ok());
        }
Ejemplo n.º 5
0
        //TODO update teacher tylko zmiana klasy itp. zaciagnac i zmodyfikowac
        public void UpdateTeacher(long id, TeacherDto teacherDto)
        {
            using (var context = _contextFactory.Create())
            {
                var teacher = new Teacher()
                {
                    Id = id
                };
                context.Teachers.Attach(teacher);


                var entry = context.Entry(teacher);
                if (teacher.Person.Name != teacherDto.Name && teacherDto.Name != null)
                {
                    teacher.Person.Name = teacherDto.Name;
                    // czegu tutaj uzyc co to jest referacne, collection, property, complex property
                    entry.Property(e => e.Classes).IsModified = true;
                }
                if (teacher.Person.Surname != teacherDto.Surname && teacherDto.Surname != null)
                {
                    teacher.Person.Surname = teacherDto.Surname;
                    entry.Property(p => p.Person).IsModified = true;
                }
                context.SaveChanges();
            }
        }
Ejemplo n.º 6
0
        public int UpdateTeacher(TeacherDto teacher, int teacherID)
        {
            try
            {
                Teacher teacherObj = null;

                using (var conn = new SqlConnection(base.GetConnectionString()))
                {
                    conn.Open();
                    teacherObj = mapper.Map <TeacherDto, Teacher>(teacher);
                    teacherID  = teacherRepo.AddTeacher(teacherObj, conn, teacherID);
                    teacherLecturesRepo.DeleteTeacherLecturesForTeacher(teacherID, conn);

                    if (teacher.Lectures != null)
                    {
                        foreach (var lectureID in teacher.Lectures)
                        {
                            teacherLecturesRepo.AddTeacherLectures(teacherID, lectureID, conn);
                        }
                    }

                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error("UpdateTeacher() error. Teacher: " + teacher.FirstName + " " + teacher.LastName, e);
            }

            return(teacherID);
        }
Ejemplo n.º 7
0
        public void CreateTeacher(TeacherDto teacher)
        {
            if (teacher == null)
            {
                throw new ArgumentNullException(nameof(teacher));
            }
            var teacherEntity = new Teacher
            {
                Id          = teacher.Id,
                FirstName   = teacher.FirstName,
                LastName    = teacher.LastName,
                DateOfBirth = teacher.DateOfBirth,
                City        = teacher.City,
                Email       = teacher.Email,
                HireDate    = teacher.HireDate
            };

            Add(teacherEntity);
            Commit();

            var courseAssignment = new CourseAssignment
            {
                TeacherId = teacherEntity.Id,
                CourseId  = teacher.CourseId
            };

            _assignmentRepo.Add(courseAssignment);
            Commit();
        }
        public ActionResult ProfileViewTeacher(int id)
        {
            var tea = new TeacherDto();

            tea = ab.TeacherRegistrations.Where(x => x.Tid == id).Select(a => new TeacherDto()
            {
                Tid         = a.Tid,
                TeacherName = a.TeacherName,
                TeacherCnic = a.TeacherCnic,
                Address     = a.Address,
                Email       = a.Email,
                SubjectID   = a.SubjectID,
                Subjects    = (from sb in ab.TeacherAssigns
                               join s in ab.Subjects on sb.SS_FK equals s.SubjectID
                               where sb.TR_FK == a.Tid
                               select new SubjectsDto
                {
                    SubjectName = s.SubjectName,
                }).ToList()
            }).FirstOrDefault();

            tea.SubjectNames = string.Join(", ", tea.Subjects.Select(p => p.SubjectName.ToString()));

            return(PartialView("_ProfileViewTeacher", tea));
        }
        public ActionResult AddEditTeacher(int id = 0)
        {
            var subjects = ab.Subjects.ToList();

            ViewBag.subjects = subjects.Select(x => new SelectListItem {
                Value = x.SubjectID.ToString(), Text = x.SubjectName
            }).ToList();

            var tea = new TeacherDto();

            if (id > 0)
            {
                tea = ab.TeacherRegistrations.Where(a => a.Tid == id).Select(a => new TeacherDto
                {
                    Tid         = a.Tid,
                    TeacherName = a.TeacherName,
                    TeacherCnic = a.TeacherCnic,
                    Address     = a.Address,
                    Email       = a.Email,
                    SubjectID   = a.SubjectID,
                    SubjectIds  = ab.TeacherAssigns.Where(s => s.TR_FK == id).Select(b => b.SS_FK).ToList()
                }).FirstOrDefault();
            }

            return(PartialView("_AddEditTeacher", tea));
        }
Ejemplo n.º 10
0
        public void CreateTeacher(TeacherDto teacher)
        {
            var teacherEntity = mapper.Map <Data.Entities.Teacher>(teacher);

            teacherRepository.Add(teacherEntity);
            unitOfWork.Commit();
        }
Ejemplo n.º 11
0
        public void TeacherEdit(TeacherDto teacher)
        {
            if (teacher == null)
            {
                throw new ArgumentNullException(nameof(teacher));
            }
            var teacherEntity = GetById(teacher.Id);

            if (teacherEntity != null)
            {
                teacherEntity.Id               = teacher.Id;
                teacherEntity.FirstName        = teacher.FirstName;
                teacherEntity.LastName         = teacher.LastName;
                teacherEntity.DateOfBirth      = teacher.DateOfBirth;
                teacherEntity.City             = teacher.City;
                teacherEntity.Email            = teacher.Email;
                teacherEntity.HireDate         = teacher.HireDate;
                teacherEntity.OfficeAssignment = teacher.OfficeAssignment;
            }
            Update(teacherEntity);
            var courseAssignment = new CourseAssignment
            {
                TeacherId = teacher.Id,
                CourseId  = teacher.CourseId
            };

            _assignmentRepo.Add(courseAssignment);
            Commit();
        }
        public async Task <bool> UpdateTeacher(TeacherDto teacherDto)
        {
            var teacher = Mapper.Map <TeacherDto, Teacher>(teacherDto);

            UnitOfWork.Repo.Update(teacher);
            return(await UnitOfWork.SaveChanges() > 0);
        }
Ejemplo n.º 13
0
        public static int GetTeacherId(TeacherDto teacher)
        {
            DataTable dataTable = new DataTable();
            DataRow   dataRow;

            using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter())
            {
                // Create the command and set its properties
                dataAdapter.SelectCommand             = new OleDbCommand();
                dataAdapter.SelectCommand.Connection  = new OleDbConnection(ConnectionConfig.ConnectionString);
                dataAdapter.SelectCommand.CommandType = CommandType.Text;
                dataAdapter.SelectCommand.CommandText = getTeacher;

                // Add the parameter to the parameter collection
                dataAdapter.SelectCommand.Parameters.AddWithValue("@LastName", teacher.LastName);
                dataAdapter.SelectCommand.Parameters.AddWithValue("@Initials", teacher.Initials);

                // Fill the datatable From adapter
                dataAdapter.Fill(dataTable);

                // Get the datarow from the table
                dataRow = dataTable.Rows.Count > 0 ? dataTable.Rows[0] : null;

                return(dataRow == null ? -1 : int.Parse(dataRow[0].ToString()));
            }
        }
        public Teacher TeacherDtoToTeacher(TeacherDto teacherDto)
        {
            if (teacherDto == null)
            {
                return(null);
            }
            Teacher teacher = new Teacher();

            teacher.UserName  = teacherDto.Username;
            teacher.FirstName = teacherDto.Name;
            teacher.LastName  = teacherDto.Surname;
            teacher.Email     = teacherDto.Email;
            //TeachesSubjects ts = new TeachesSubjects();
            //if (teacherDto.Subjects != null)
            //{
            //    foreach (var subject in teacherDto.Subjects)
            //    {
            //        Subject subjectt = db.SubjectsRepository.DtoToSubject(subject);
            //        ts.Teacher = teacher;
            //        ts.Subject = subjectt;
            //        teacher.Subjects.Add(ts);
            //    }
            //}
            return(teacher);
        }
 public TeacherViewModel(TeacherDto teacherDto)
 {
     Id = teacherDto.Id;
     TestPassingList = teacherDto.TestPassingList;
     CoursesList     = teacherDto.CoursesList;
     GroupsList      = teacherDto.GroupsList;
 }
        public async Task <IActionResult> Put([FromRoute] string id, [FromBody] TeacherDto teacher)
        {
            teacher.Id = id;
            var result = await teachersService.UpdateAsync(teacher);

            return(NoContent());
        }
Ejemplo n.º 17
0
 private static void AssertAreEqual(TeacherDto teacherDto, Teacher teacher)
 {
     Assert.AreEqual(teacherDto.LastName, teacher.LastName);
     Assert.AreEqual(teacherDto.FirstName, teacher.FirstName);
     Assert.AreEqual(teacherDto.MiddleName, teacher.MiddleName);
     Assert.AreEqual(teacherDto.Phone, teacher.Phone);
     Assert.AreEqual(teacherDto.SubjectsIds, teacher.Subjects.Select(subject => subject.Id));
 }
Ejemplo n.º 18
0
        public async Task <string> CreateAsync(TeacherDto teacher)
        {
            var result = teachersRepository.Add(teacher.To <Teacher>());

            await teachersRepository.SaveChangesAsync();

            return(result.Id);
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Register(UserDto userDto)
        {
            try
            {
                // creating user
                var user = _mapper.Map <User>(userDto);

                var result = await _userManager.CreateAsync(user, userDto.Password);

                var userToReturn = _mapper.Map <UserDto>(user);

                if (userDto.UserRole == "student")
                {
                    StudentDto studentDto = new StudentDto();
                    studentDto.Name     = userDto.FullName;
                    studentDto.Id       = user.Id;
                    studentDto.PhotoURL = "";
                    studentDto.Email    = user.Email;

                    var student = _mapper.Map <Student>(studentDto);

                    _repository.Add(student);

                    if (await _repository.SaveChangesAsync())
                    {
                        return(Created($"/api/student/{studentDto.Id}", _mapper.Map <StudentDto>(student)));
                    }
                }
                else if (userDto.UserRole == "teacher")
                {
                    TeacherDto teacherDto = new TeacherDto();
                    teacherDto.Name     = userDto.FullName;
                    teacherDto.Id       = user.Id;
                    teacherDto.PhotoURL = "";
                    teacherDto.Email    = user.Email;

                    var teacher = _mapper.Map <Teacher>(teacherDto);

                    _repository.Add(teacher);

                    if (await _repository.SaveChangesAsync())
                    {
                        return(Created($"/api/teacher/{teacherDto.Id}", _mapper.Map <TeacherDto>(teacher)));
                    }
                }

                if (result.Succeeded)
                {
                    return(Created("GetUser", userToReturn));
                }

                return(BadRequest(result.Errors));
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco Dados Falhou {ex.Message}"));
            }
        }
Ejemplo n.º 20
0
        public IActionResult Add(TeacherDto aTeacher)
        {
            Teacher myTeacher = _mapper.Map <Teacher>(aTeacher);

            myTeacher = _repo.Add(myTeacher);
            var myResponse = _mapper.Map <TeacherDto>(myTeacher);

            return(Ok(myResponse));
        }
        public void Execute(TeacherDto request)
        {
            _validator.ValidateAndThrow(request);
            var teacher = _mapper.Map <Teacher>(request);

            _context.Teachers.Add(teacher);

            _context.SaveChanges();
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> CreateTeacher(TeacherDto teacherDto)
        {
            var teacher = _mapper.Map <Student>(teacherDto);

            _repo.Add(teacher);
            await _repo.SaveAll();

            return(Ok());
        }
        public IHttpActionResult GetTeacher([FromUri] Guid id)
        {
            TeacherDto teacher = db.GetTeacher(id);

            if (teacher == null)
            {
                return(NotFound());
            }
            return(Ok(teacher));
        }
        public async Task <IActionResult> PostTeacher([FromBody] TeacherDto teacherDto)
        {
            if (teacherDto == null)
            {
                return(BadRequest("Teacher is null!"));
            }
            var result = await teachersService.CreateAsync(teacherDto);

            return(Created(new Uri("https://localhost:4"), result));
        }
        public IHttpActionResult UpdateTeacher(int teacherId, TeacherDto dto)
        {
            var result = _teacherService.Update(teacherId, dto);

            if (result == null)
            {
                return(BadRequest());
            }

            return(Ok(result));
        }
Ejemplo n.º 26
0
        public IActionResult EditTeacher(TeacherDto teacher)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            PopulateCoursesDropDownList(teacher.CourseId);
            _teacherService.TeacherEdit(teacher);
            return(View(teacher));
        }
Ejemplo n.º 27
0
        public IActionResult CreatePost(TeacherDto newTeacher)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            PopulateCoursesDropDownList(newTeacher.CourseId);
            _teacherService.CreateTeacher(newTeacher);
            return(View(newTeacher));
        }
Ejemplo n.º 28
0
        private TeacherDto GetTeacherDto(ApplicationUser user)
        {
            TeacherDto teacher = new TeacherDto(user);

            teacher.Subjects = _db.TeacherToSubjects.Where(t => t.TeacherId == user.Id)
                               .Join(_db.Subjects, t => t.SubjectId, s => s.Id, (t, s) => s).ToList();
            var department = _db.Departments.Find(user.GroupId);

            teacher.Department = department.NameAbridgment;
            teacher.Comments   = CommentsToTeacherDto(user.Id);
            return(teacher);
        }
Ejemplo n.º 29
0
        public TeacherDto GetTeacher(int id)
        {
            Teacher    teacher    = lernsiegService.GetTeacher(id);
            TeacherDto teacherDto = new TeacherDto
            {
                Id    = teacher.Id,
                Name  = teacher.Name,
                Title = teacher.Title
            };

            return(teacherDto);
        }
Ejemplo n.º 30
0
        public TeacherDto GetTeacher(Guid id)
        {
            Teacher teacher = db.TeachersRepository.GetByID(id.ToString());

            if (teacher == null)
            {
                return(null);
            }
            TeacherDto user = TeachertoTeacherDto(teacher);

            return(user);
        }
Ejemplo n.º 31
0
 public ActionResult Add(TeacherDto teacher)
 {
     return RedirectToAction("Index");
 }