示例#1
0
        public ActionResult DeleteTeacher(int id)
        {
            var TeacherModelFromDB = _repo.GetTeacherById(id);

            if (TeacherModelFromDB == null)
            {
                throw new ArgumentNullException(nameof(TeacherModelFromDB));
            }
            _repo.DeleteTeacher(TeacherModelFromDB);
            _repo.SaveChanges();

            return(NoContent());
        }
示例#2
0
        public IHttpActionResult GetTeacher(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(BadRequest());
            }
            Teacher teacherEntity = _repo.GetTeacherById(id);

            if (teacherEntity == null)
            {
                return(NotFound());
            }
            if (!HasAccesToTeacher(id))
            {
                return(ResponseMessage(new HttpResponseMessage(HttpStatusCode.Forbidden)));
            }

            var teacher = new TeacherBasicDto()
            {
                Id              = teacherEntity.Id,
                UserName        = teacherEntity.UserName,
                FullName        = teacherEntity.FullName,
                FirstName       = teacherEntity.FirstName,
                LastName        = teacherEntity.LastName,
                Email           = teacherEntity.Email,
                PhoneNumber     = teacherEntity.PhoneNumber,
                UpcomingCourses = teacherEntity.Courses.Select(c => new CourseDto()
                {
                    Id              = c.Id,
                    Name            = c.Name,
                    StudentsGroupId = c.StudentsGroupId,
                    Room            = c.Room,
                    TeacherId       = c.TeacherId,
                    DaySchedules    = c.DaySchedules.Select(d => new DayScheduleDto()
                    {
                        Day       = d.Day,
                        Id        = d.Id,
                        EndTime   = d.EndTime,
                        StartTime = d.StartTime
                    })
                })
            };

            return(Ok(teacher));
        }