/// <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; }
public async Task <SpecialityDto> UpdateSpecialityAsync([FromBody] SpecialityRequest request, CancellationToken cancellationToken) { var result = await _specialityService.UpdateSpecialityAsync(request, cancellationToken) .ConfigureAwait(false); return(result); }
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(); } }
///<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); } }
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")); } }
///<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()); } }
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)); } }
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")); } }
/// <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; }
public async Task <string> NewSpeciality(SpecialityRequest speciality) { var response = await PostStatusCode(FirstVersion, "/Specialities/Create", speciality); return(response.Message); }
public async Task AddSpecialityAsync([FromBody] SpecialityRequest request, CancellationToken cancellationToken) { await _specialityService.AddSpecialityAsync(request, cancellationToken).ConfigureAwait(false); }