public async Task <ServiceResult <SubjectDto> > CreateSubjectAsync(SubjectAddRequest request) { var validationResult = await PerformSubjectValidation(request.FacultyId, request.TeacherId); if (!validationResult.IsSuccess) { return(validationResult); } var newSubject = new Subject() { Title = request.Title, TeacherId = request.TeacherId, Description = request.Description, FacultyId = request.FacultyId, Avatar = request.Avatar }; if (string.IsNullOrEmpty(newSubject.Avatar)) { newSubject.Avatar = _urlOptions.ServerUrl + DefaultImagesConstants.DefaultImage; } _unitOfWork.SubjectRepository.Add(newSubject); await _unitOfWork.CommitAsync(); return(ServiceResult <SubjectDto> .Ok(_mapper.Map <Subject, SubjectDto>(newSubject))); }
public async Task <ActionResult <SubjectDto> > AddSubjectAsync([FromBody] SubjectAddRequest request) => _viewMapper.ServiceResultToContentResult( await _subjectService.CreateSubjectAsync(request));