public async Task <UniversityDto> UpdateUniversityAsync([FromBody] UniversityRequest request,
                                                                CancellationToken cancellationToken)
        {
            var result = await _universityService.UpdateUniversitiesAsync(request, cancellationToken).ConfigureAwait(false);

            return(result);
        }
        public async Task <UniversitySearchDto> GetAsync([FromQuery] UniversityRequest model,
                                                         [ProfileModelBinder(ProfileServiceQuery.Country)] UserProfile profile,
                                                         CancellationToken token)
        {
            var result = await _universityProvider.SearchAsync(model.Term, model.Page,
                                                               profile.Country, token);

            return(result);
        }
        /// <inheritdoc/>
        public async Task AddUniversityAsync(UniversityRequest request, CancellationToken cancellationToken)
        {
            using (var scope = _serviceProvider.CreateScope())
                using (var context = scope.ServiceProvider.GetRequiredService <DatabaseContext>())
                {
                    await context.AddAsync(new UniversityEntity(request), cancellationToken).ConfigureAwait(false);

                    await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
                }
        }
Beispiel #4
0
    UniversityRequest GetRequestInfo()
    {
        // Get the Json from the POST.
        string      strJson = String.Empty;
        HttpContext context = HttpContext.Current;

        context.Request.InputStream.Position = 0;
        using (StreamReader inputStream = new StreamReader(context.Request.InputStream))
        {
            strJson = inputStream.ReadToEnd();
        }

        // Deserialize the Json.
        UniversityRequest request = JsonConvert.DeserializeObject <UniversityRequest>(strJson);

        return(request);
    }
        /// <inheritdoc/>
        public async Task <UniversityDto> UpdateUniversitiesAsync(UniversityRequest request, CancellationToken cancellationToken)
        {
            using (var scope = _serviceProvider.CreateScope())
                using (var context = scope.ServiceProvider.GetRequiredService <DatabaseContext>())
                {
                    var universityEntity = await context.Universities
                                           .FirstOrDefaultAsync(x => x.FullName == request.FullName, cancellationToken).ConfigureAwait(false);

                    if (universityEntity == null)
                    {
                        throw new NotFoundException("University not found.");
                    }

                    universityEntity.LevelOfAccreditation = request.LevelOfAccreditation;

                    await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

                    return(universityEntity.ToDto());
                }
        }
 public async Task AddUniversityAsync([FromBody] UniversityRequest request, CancellationToken cancellationToken)
 {
     await _universityService.AddUniversityAsync(request, cancellationToken).ConfigureAwait(false);
 }
Beispiel #7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="request"><see cref="UniversityRequest"/> instance.</param>
 public UniversityEntity(UniversityRequest request)
 {
     FullName             = request.FullName;
     LevelOfAccreditation = request.LevelOfAccreditation;
 }