Пример #1
0
 private async void btnSave_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         view.ArtType = null;
         ArtworkRepository er = new ArtworkRepository();
         if (view.ID == 0)
         {
             await er.AddArtwoork(view);
         }
         else
         {
             await er.UpdateArtwork(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(string.Format(" HTTP Status Code: {0}", apiEx.StatusCode.ToString()));
         sb.AppendLine("Errors:");
         foreach (var error in apiEx.Errors)
         {
             sb.AppendLine("-" + error);
         }
         Common.ShowMessage("Problem Saving the Patient:", sb.ToString());
     }
     catch (Exception ex)
     {
         if (ex.InnerException.Message.Contains("connection with the server"))
         {
             Common.ShowMessage("Error", "No connection with the server.");
         }
         else
         {
             Common.ShowMessage("Error", "Could not complete operation.");
         }
     }
 }
        public async Task <IActionResult> PutArtwork([FromRoute] int id, [FromBody] Artwork artwork)
        {
            try
            {
                if (artwork == null)
                {
                    logger.LogError("Artwork object sent was null");
                    return(BadRequest("Artwork object is null"));
                }

                if (!id.Equals(artwork.Id))
                {
                    logger.LogError("Invalid artwork id");
                    return(BadRequest("Invalid artwork id"));
                }


                if (!ModelState.IsValid)
                {
                    logger.LogError("Invalid artwork object sent from client");
                    return(BadRequest("Invalid artwork object"));
                }

                if (!artworkRepository.ArtworkExists(id))
                {
                    logger.LogError("Artwork does not exist in the database");
                    return(BadRequest("Artwork does not exist in the database"));
                }


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

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