Exemple #1
0
        public async Task <ActionResult> Post([FromBody] CreateTeacherDTO TeacherDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            await _teacherService.CreateAsync(TeacherDTO);

            return(Ok());
        }
Exemple #2
0
        public async Task <IHttpActionResult> PostTeacher(CreateTeacherDTO teacher)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await TeacherService.AddTeacher(teacher);

            if (!result.Created)
            {
                return(BadRequest("Adding teacher error. Try again."));
            }

            return(CreatedAtRoute("GetTeacher", new { id = result.Teacher.TeacherId }, result.Teacher));
        }
Exemple #3
0
        public async Task <NewTeacherResultDTO> AddTeacher(CreateTeacherDTO teacherDTO)
        {
            var createResult = new NewTeacherResultDTO
            {
                Created = false,
                Teacher = null
            };
            var user = new ApplicationUser {
                UserName = teacherDTO.Email, Email = teacherDTO.Email, CreatedDate = DateTime.Now, FirstName = teacherDTO.FirstName, LastName = teacherDTO.LastName, EmailConfirmed = true
            };

            var result = await _userManager.CreateAsync(user, teacherDTO.Pesel.ToString() + teacherDTO.LastName.ToLower().Substring(0, Math.Min(teacherDTO.LastName.Length, 3)));

            var roleResult = await _userManager.AddToRoleAsync(user.Id, "teacher");

            if (!result.Succeeded && !roleResult.Succeeded)
            {
                return(createResult);
            }

            var teacher = Mapper.Map <Teacher>(teacherDTO);

            teacher.UserId = user.Id;

            var createdTeacher = _repository.InsertTeacher(teacher);

            if (_repository.Save())
            {
                createResult.Created = true;
                createResult.Teacher = Mapper.Map <GetTeacherDTO>(createdTeacher);

                return(createResult);
            }

            return(createResult);
        }
        public async Task CreateAsync(CreateTeacherDTO TeacherDto)
        {
            var teacher = _mapper.Map <School.Domain.Teacher>(TeacherDto);

            await this._repository.CreateAsync(teacher);
        }