Exemplo n.º 1
0
        private async void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            string strTitle            = "Confirm Delete";
            string strMsg              = "Are you certain that you want to delete " + view.Name + "?";
            ContentDialogResult result = await Common.ConfirmDialog(strTitle, strMsg);

            if (result == ContentDialogResult.Secondary)
            {
                try
                {
                    view.ArtType = null;
                    ArtworkRepository er = new ArtworkRepository();
                    await er.DeleteArtwork(view);

                    Frame.GoBack();
                }
                catch (AggregateException ex)
                {
                    string errMsg = "";
                    foreach (var exception in ex.InnerExceptions)
                    {
                        errMsg += Environment.NewLine + exception.Message;
                    }
                    Common.ShowMessage("One or more exceptions has occurred:", errMsg);
                }
                catch (ApiException apiEx)
                {
                    var sb = new StringBuilder();
                    sb.AppendLine("Errors:");
                    foreach (var error in apiEx.Errors)
                    {
                        sb.AppendLine("-" + error);
                    }
                    Common.ShowMessage("Problem Deleting the Patient:", sb.ToString());
                }
                catch (Exception)
                {
                    Common.ShowMessage("Error", "Error Deleting Patient");
                }
            }
        }
        public async Task <IActionResult> deleteArtwork(int id)
        {
            try
            {
                var artwork = await artworkRepository.GetArtworkById(id);

                if (artwork == null)
                {
                    logger.LogError($"Artwork object with id {id} has not been found in the database");
                    return(NotFound());
                }


                artworkRepository.DeleteArtwork(artwork);
                await artworkRepository.saveChanges();

                return(Ok("Artwork has been deleted"));
            }
            catch (Exception exception)
            {
                logger.LogError($"Something went wrong internally in the server: ", exception.Message);
                return(StatusCode(500, "Internal server error"));
            }
        }