示例#1
0
        public async Task <IActionResult> Add([FromForm] IFormFile file, AddSpeakingClubRequest request)
        {
            if (Request.CheckPassword(_credentials.Password))
            {
                var teacher = (await _cespRepository.GetTeachers())
                              .FirstOrDefault(t => t.Name.Equals(request.TeacherName, StringComparison.OrdinalIgnoreCase));
                var languageLevel = (await _cespRepository.GetLanguageLevel(request.LanguageLevelName));
                if (teacher == null || languageLevel == null)
                {
                    return(BadRequest());
                }
                await _fileManager.SaveContent(file, "club");

                var speakingClub = _mapper.Map <SpeakingClubMeeting>(request);
                speakingClub.FileName = $"club/{file.FileName}";
                var speakingClubDto = _mapper.Map <SpeakingClubMeetingDto>(speakingClub);
                speakingClubDto.Teacher          = teacher;
                speakingClubDto.MinLanguageLevel = languageLevel;

                await _cespRepository.AddSpeakingClubMeeting(speakingClubDto);

                return(Ok());
            }

            return(BadRequest());
        }