public static void HandleDeleteBook(IMessage message, IConnection connection) { DeleteBookMessage bookMessage = message as DeleteBookMessage; string login = Conn.GetLoginFor(bookMessage.Token); if (login == null) { SendStatusError(connection, "Вы не авторизованы."); return; } try { if (!Conn.HasBook(login, bookMessage.BookId)) { SendStatusError(connection, "Эта книга вам не принадлежит."); return; } } catch { SendStatusError(connection, "Внутренняя ошибка с базой данных."); return; } // Deleting book try { Conn.DeleteBook(bookMessage.BookId); SendStatusOk(connection, "Книга удалена из базы."); } catch (Exception e) { SendStatusError(connection, "Книга не удалена: " + e.Message); } }
private async void DeleteBook(DeleteBookMessage msg) { var deleteButton = "Delete"; var deleteSyncButton = "Delete including all synchronizations"; var confirm = await DisplayActionSheet("Delete book?", deleteButton, "No", deleteSyncButton); if (confirm == deleteButton || confirm == deleteSyncButton) { var card = Bookshelf.Children.FirstOrDefault(o => o.StyleId == msg.Book.ID); if (card != null) { Bookshelf.Children.Remove(card); } _bookshelfService.RemoveById(msg.Book.ID); if (confirm == deleteSyncButton) { _syncService.DeleteBook(msg.Book.ID); } } }