Пример #1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="request"><see cref="SpecialityRequest"/> instance.</param>
 public SpecialityEntity(SpecialityRequest request)
 {
     Code          = request.Code;
     Name          = request.Name;
     Faculty       = request.Faculty;
     SubjectScores = request.SubjectScores;
 }
Пример #2
0
        public async Task <SpecialityDto> UpdateSpecialityAsync([FromBody] SpecialityRequest request,
                                                                CancellationToken cancellationToken)
        {
            var result = await _specialityService.UpdateSpecialityAsync(request, cancellationToken)
                         .ConfigureAwait(false);

            return(result);
        }
Пример #3
0
        public async Task AddSpecialityTask(SpecialityRequest request)
        {
            using (var context = _serviceProvider.GetService <DatabaseContext>())
            {
                var specialityEntity = new SpecialityEntity(request);

                await context.Specialtys.AddAsync(specialityEntity);

                await context.SaveChangesAsync();
            }
        }
Пример #4
0
        ///<inheritdoc/>
        public async Task AddSpecialityAsync(SpecialityRequest request, CancellationToken cancellationToken)
        {
            using (var scope = _serviceProvider.CreateScope())
                using (var context = scope.ServiceProvider.GetRequiredService <DatabaseContext>())
                {
                    var specialityEntity = new SpecialityEntity(request);

                    await context.Specialties.AddAsync(specialityEntity, cancellationToken).ConfigureAwait(false);

                    await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
                }
        }
Пример #5
0
        public async Task <IActionResult> AddSpecialityAsync([FromBody] SpecialityRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                await _specialityService.AddSpecialityTask(request);

                return(StatusCode(200));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(StatusCode(500, "Internal server error"));
            }
        }
Пример #6
0
        ///<inheritdoc/>
        public async Task <SpecialityDto> UpdateSpecialityAsync(SpecialityRequest request, CancellationToken cancellationToken)
        {
            using (var scope = _serviceProvider.CreateScope())
                using (var context = scope.ServiceProvider.GetRequiredService <DatabaseContext>())
                {
                    var specialityEntity = await context.Specialties
                                           .FirstOrDefaultAsync(x => x.Code == request.Code, cancellationToken).ConfigureAwait(false);

                    if (specialityEntity == null)
                    {
                        throw new NotFoundException("Speciality not found.");
                    }

                    specialityEntity.Update(request);

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

                    return(specialityEntity.ToDto());
                }
        }
Пример #7
0
        public async Task <SpecialityDto> EditSpecialityTask(SpecialityRequest request)
        {
            using (var context = _serviceProvider.GetService <DatabaseContext>())
            {
                var specialityEntity = await context.Specialtys
                                       .FirstOrDefaultAsync(x => x.Code == request.Code);

                if (specialityEntity == null)
                {
                    throw new SpecialityNotFoundException();
                }

                specialityEntity.AdditionalFactor   = request.AdditionalFactor;
                specialityEntity.CountOfStatePlaces = request.CountOfStatePlaces;
                specialityEntity.Name = request.Name;

                await context.SaveChangesAsync();

                return(new SpecialityDto(specialityEntity));
            }
        }
Пример #8
0
        public async Task <IActionResult> EditSpecialityAsync([FromBody] SpecialityRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var result = await _specialityService.EditSpecialityTask(request);

                return(StatusCode(200, result));
            }
            catch (SpecialityNotFoundException ex)
            {
                return(StatusCode(404, ex.Message));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(StatusCode(500, "Internal server error"));
            }
        }
Пример #9
0
 /// <summary>
 /// Method for update speciality.
 /// </summary>
 /// <param name="request"><see cref="SpecialityRequest"/> instance.</param>
 public void Update(SpecialityRequest request)
 {
     Faculty       = request.Faculty;
     SubjectScores = request.SubjectScores;
     Name          = request.Name;
 }
Пример #10
0
        public async Task <string> NewSpeciality(SpecialityRequest speciality)
        {
            var response = await PostStatusCode(FirstVersion, "/Specialities/Create", speciality);

            return(response.Message);
        }
Пример #11
0
 public async Task AddSpecialityAsync([FromBody] SpecialityRequest request, CancellationToken cancellationToken)
 {
     await _specialityService.AddSpecialityAsync(request, cancellationToken).ConfigureAwait(false);
 }