public async Task <ActionResult> DeletePhoneBook(Guid id) { // Check if the phone book exists PhoneBook phoneBook = await _phoneBookRepository.GetByIdAsync(id); if (phoneBook == null) { return(NotFound()); } // Check if the phone book belongs to the current user Guid userId = Guid.Parse(_userInfoService.UserId); if (phoneBook.UserId == userId) { _phoneBookRepository.Delete(phoneBook); await _phoneBookRepository.SaveChangesAsync(); return(NoContent()); } _logger.LogWarning("User with id {ForbiddenUser} attempted to delete a phone book owned by {OwningUser}", userId, phoneBook.UserId); // the phone book does not belong to the user // forbidden request return(Forbid()); }
public async Task <IActionResult> DeletePhoneBook(int Id) { _ = new ObjectResult(false); try { var PhoneBook = await _PhoneBookApi.GetPhoneBookByID(Id); if (PhoneBook == null) { return(NotFound(new { message = "Phone Books not found" })); } else { _PhoneBookApi.Delete(PhoneBook); return(Ok(new { message = "PhoneNumber is deleted successfully." })); } } catch (Exception ex) { _loggingApi.Add(new SYS_Error() { Message = ex.Message, StackTrace = ex.StackTrace, CreatedDate = DateTime.Now }); await _loggingApi.Commit(); return(NotFound(new { message = "An error occured" })); } }
public void DeletePhoneBook(long id) { var entry = GetPhoneBookById(id); _phoneBookRepository.Delete(entry); _phoneBookRepository.Save(); }
public IActionResult Delete(Guid id) { if (id == Guid.Empty) { return(NotFound()); } var phoneBook = _productRepository.Get(id); if (phoneBook == null) { return(NotFound()); } _productRepository.Delete(id); return(Ok()); }
public bool Delete(int id) { bool deleted = _phoneBookRepository.Delete(id); return(deleted); }
public bool Delete(int?phoneBookId) { var entry = _phoneBookRepo.Get(u => u.Id == phoneBookId, _context); return(entry != null?_phoneBookRepo.Delete(entry, _context) : false); }
public Task HandleAsync(DeletePhoneBook command) { _repository.Delete(command.Id); return(Task.CompletedTask); }
public void Delete(Guid id) { _phoneBookRepository.Delete(_context, id); }