public async Task <IActionResult> UpdateTestCenter(int?id, TestCenterDto testCenterDto) { if (id == null) { return(BadRequest()); } var tesCenterInDb = await _unitOfWork.TestCenters.GetByIdAsync(id.Value); if (tesCenterInDb != null) { tesCenterInDb.City = testCenterDto.City; tesCenterInDb.SlotCapacity = testCenterDto.SlotCapacity; tesCenterInDb.Street = testCenterDto.Street; tesCenterInDb.Name = testCenterDto.Name; tesCenterInDb.Postalcode = testCenterDto.Postalcode; try { _unitOfWork.TestCenters.Update(tesCenterInDb); return(Ok(await _unitOfWork.SaveChangesAsync())); } catch (Exception ex) { return(BadRequest(ex.Message)); } } else { return(NotFound()); } }
public async Task <ActionResult> PostTestCenter(TestCenterDto testCenterDto) { if (!ModelState.IsValid) { return(BadRequest()); } if (testCenterDto == null) { return(BadRequest()); } var testCenter = testCenterDto.ToTestCenter(); await _unitOfWork.TestCenterRepository.AddAsync(testCenter); try { await _unitOfWork.SaveChangesAsync(); return(CreatedAtAction( nameof(GetTestCenter), new { id = testCenter.Id }, new TestCenterDto(testCenter))); } catch (ValidationException ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> CreateTestCenter(TestCenterDto testCenterDto) { if (!ModelState.IsValid) { return(BadRequest()); } var newTestCenter = new TestCenter { City = testCenterDto.City, SlotCapacity = testCenterDto.SlotCapacity, Street = testCenterDto.Street, Name = testCenterDto.Name, Postalcode = testCenterDto.Postalcode }; try { await _unitOfWork.TestCenters.AddAsync(newTestCenter); await _unitOfWork.SaveChangesAsync(); return(CreatedAtAction( nameof(Get), new { id = newTestCenter.Id }, newTestCenter)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult> PutTestCenter(int?id, TestCenterDto testCenterDto) { if (id == null) { return(BadRequest()); } TestCenter testCenter = await _unitOfWork.TestCenterRepository.GetTestCenterByIdAsync(id.Value); if (testCenter == null) { return(NotFound()); } testCenter.Name = testCenterDto.Name; testCenter.City = testCenterDto.City; testCenter.Postcode = testCenterDto.Postcode; testCenter.Street = testCenterDto.Street; testCenter.SlotCapacity = testCenterDto.SlotCapacity; try { await _unitOfWork.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(NoContent()); }