public async Task <IActionResult> Add([FromForm] IFormFile file, [FromForm] IFormFile fileSmall, [FromForm] IFormFile fileLarge, AddTeacherRequest request) { if (Request.CheckPassword(_credentials.Password)) { await _fileManager.SaveContent(file, FileFolder); await _fileManager.SaveContent(fileSmall, FileFolder); await _fileManager.SaveContent(fileLarge, FileFolder); var teacherDto = _mapper.Map <TeacherDto>(request); teacherDto.Photo = new FileDto { Info = request.Name, Name = AddFileFolder(file.FileName) }; teacherDto.SmallPhoto = new FileDto { Info = request.Name, Name = AddFileFolder(fileSmall.FileName) }; teacherDto.LargePhoto = new FileDto { Info = request.Name, Name = AddFileFolder(fileLarge.FileName) }; await _cespRepository.AddTeacher(teacherDto); return(Ok()); } return(BadRequest()); }
public IActionResult AddTeacher(AddTeacherRequest request) { if (request == null) { return(BadRequest()); } if (!TokenProvider.IsAdmin(User)) { return(Unauthorized()); } var lehrer = new Lehrer() { Name = request.name, Email = request.email, Administrator = request.admin }; using (var sha = SHA256.Create()) { lehrer.Password = Convert.ToBase64String( sha.ComputeHash(Encoding.UTF8.GetBytes(request.password + LoginController.SALT))); } context.Lehrer.Add(lehrer); return(Ok()); }
public async Task addTeacher_should_add_correct_entity() { var teacher = new AddTeacherRequest { Firstname = "Marek" }; var addedTeacher = await _sut.AddTeacherAsync(teacher); addedTeacher.ShouldNotBeNull(); addedTeacher.Firstname.ShouldBe("Marek"); }
public async Task <TeacherResponse> AddTeacherAsync(AddTeacherRequest request) { if (request == null) { throw new ArgumentNullException($"Entity is null"); } var teacher = _teacherMapper.Map(request); var result = _teacherRepository.Create(teacher); await _teacherRepository.UnitOfWork.SaveChangesAsync(); return(_teacherMapper.Map(result)); }
public Teacher Map(AddTeacherRequest request) { if (request == null) { return(null); } var teacher = new Teacher { Firstname = request.Firstname, Lastname = request.Lastname, SchoolId = request.SchoolId, }; return(teacher); }
public async Task <IActionResult> AddTeacherAsync([FromBody] AddTeacherRequest request) { CourseDTO course = await courseService.GetCourseByIdAsync(request.CourseId); if (course == null) { throw new BadRequestException("Course doesn't exist"); } if (!await User.IsUniversityTeacherOrHigherAsync(course.UniversityId, universityService)) { throw new ForbiddenException("Don't have rights to access the course!"); } await courseService.AddCourseMemberAsync(request.CourseId, request.TeacherEmail); return(Ok()); }
public async Task add_should_create_new_record() { var request = new AddTeacherRequest() { Firstname = "Sean", Lastname = "Diaz", SchoolId = 1 }; var client = _factory.CreateClient(); var httpsContent = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); var response = await client.PostAsync($"/api/teachers", httpsContent); response.EnsureSuccessStatusCode(); response.Headers.Location.ShouldNotBeNull(); }
public async Task <IActionResult> Post(AddTeacherRequest request) { var result = await _teacherService.AddTeacherAsync(request); return(CreatedAtAction(nameof(GetById), new { id = result.Id }, null)); }