예제 #1
0
        public async Task <ServiceResult <UniversityDto> > CreateUniversityAsync(UniversityAddRequest request)
        {
            if (!await _unitOfWork.CityRepository.IsExistById(request.CityId))
            {
                return(ServiceResult <UniversityDto> .Fail(EOperationResult.EntityNotFound, "City with this Id doesn't exist"));
            }

            var newUniversity = new University()
            {
                FullTitle   = request.FullTitle,
                ShortTitle  = request.ShortTitle,
                Description = request.Description,
                CityId      = request.CityId,
                Avatar      = DefaultImagesConstants.DefaultImage
            };

            if (string.IsNullOrEmpty(newUniversity.Avatar))
            {
                newUniversity.Avatar = DefaultImagesConstants.DefaultImage;
            }

            _unitOfWork.UniversityRepository.Add(newUniversity);

            await _unitOfWork.CommitAsync();

            return(ServiceResult <UniversityDto> .Ok(_mapper.Map <University, UniversityDto>(newUniversity)));
        }
예제 #2
0
 public async Task <ActionResult <UniversityDto> > AddUniversityAsync([FromBody] UniversityAddRequest request)
 {
     return(_viewMapper.ServiceResultToContentResult(await _universityService.CreateUniversityAsync(request)));
 }