| await result; | await result; | ||||
| } | } | ||||
| public async Task ArchiveAdAsync(int id) | |||||
| { | |||||
| _logger.LogInformation($"Start searching Ad with id = {id}"); | |||||
| var ad = await _context.Ads.FindAsync(id); | |||||
| if (ad is null) | |||||
| { | |||||
| _logger.LogError($"Ad with id = {id} not found"); | |||||
| throw new EntityNotFoundException("Ad not found"); | |||||
| } | |||||
| _logger.LogInformation($"Change ad expired time"); | |||||
| ad.ExpiredAt = DateTime.UtcNow; | |||||
| _logger.LogInformation($"Ad expired time changed successfully"); | |||||
| _context.Entry(ad).State = EntityState.Modified; | |||||
| var result = _context.SaveChangesAsync(); | |||||
| _logger.LogInformation($"Ad saved to DB"); | |||||
| await result; | |||||
| } | |||||
| public async Task DeleteAsync(int id) | public async Task DeleteAsync(int id) | ||||
| { | { | ||||
| _logger.LogInformation($"Start searching Ad with id = {id}"); | _logger.LogInformation($"Start searching Ad with id = {id}"); |
| FirstName = userk.FirstName, | FirstName = userk.FirstName, | ||||
| LastName = userk.LastName, | LastName = userk.LastName, | ||||
| Username = userk.UserName, | Username = userk.UserName, | ||||
| Token = model.Token, | |||||
| RefreshToken = model.RefreshToken | |||||
| Token = token, | |||||
| RefreshToken = token | |||||
| } | } | ||||
| }; | }; | ||||
| } | } |
| Task UpdateAsync(int id, AdUpdateDto adUpdateDto); | Task UpdateAsync(int id, AdUpdateDto adUpdateDto); | ||||
| Task ArchiveAdAsync(int id); | |||||
| Task DeleteAsync(int id); | Task DeleteAsync(int id); | ||||
| } | } | ||||
| } | } |
| return Ok(); | return Ok(); | ||||
| } | } | ||||
| [HttpPut("archive-active-ad/{id}")] | |||||
| public async Task<IActionResult> ArchiveActiveAd([FromRoute] int id) | |||||
| { | |||||
| await _adService.ArchiveAdAsync(id); | |||||
| return Ok(); | |||||
| } | |||||
| [HttpDelete("{id}")] | [HttpDelete("{id}")] | ||||
| public async Task<IActionResult> DeleteAd([FromRoute]int id) | public async Task<IActionResult> DeleteAd([FromRoute]int id) | ||||
| { | { |