From 57aba2f39558bfe41a2c76d5b31e4c7241a47c41 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Fri, 17 Jan 2025 16:45:23 +0330 Subject: [PATCH] Ganjoor Museum: update an artifact item #463 --- RMuseum/Controllers/ArtifactController.cs | 19 +++++++++++++++++ RMuseum/RMuseum.xml | 21 +++++++++++++++++++ RMuseum/Services/IArtifactService.cs | 6 ++++++ .../Implementation/ArtifactService.cs | 21 +++++++++++++++++++ 4 files changed, 67 insertions(+) diff --git a/RMuseum/Controllers/ArtifactController.cs b/RMuseum/Controllers/ArtifactController.cs index f25c7425..11ecc834 100644 --- a/RMuseum/Controllers/ArtifactController.cs +++ b/RMuseum/Controllers/ArtifactController.cs @@ -1101,6 +1101,25 @@ namespace RMuseum.Controllers return Ok(itemInfo.Result); } + + /// + /// update an artifact item info + /// + /// + /// + [HttpPut("item")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task UpdateArtifactItemRecordAsync([FromBody]RArtifactItemRecord item) + { + var res = await _artifactService.UpdateArtifactItemRecordAsync(item); + if(!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(); + } + /// /// gets specified publish artifact item info (including images + attributes) /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 2664d3f5..89073256 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -312,6 +312,13 @@ + + + update an artifact item info + + + + gets specified publish artifact item info (including images + attributes) @@ -14994,6 +15001,13 @@ + + + update artifact item + + + + add new artifact @@ -17726,6 +17740,13 @@ + + + update artifact item + + + + add new artifact diff --git a/RMuseum/Services/IArtifactService.cs b/RMuseum/Services/IArtifactService.cs index b503b8ea..ac046082 100644 --- a/RMuseum/Services/IArtifactService.cs +++ b/RMuseum/Services/IArtifactService.cs @@ -248,6 +248,12 @@ namespace RMuseum.Services /// Task> GetArtifactItemByFrienlyUrl(string artifactUrl, string itemUrl, PublishStatus[] statusArray); + /// + /// update artifact item + /// + /// + /// + Task> UpdateArtifactItemRecordAsync(RArtifactItemRecord item); /// diff --git a/RMuseum/Services/Implementation/ArtifactService.cs b/RMuseum/Services/Implementation/ArtifactService.cs index 86b5074a..81f858df 100644 --- a/RMuseum/Services/Implementation/ArtifactService.cs +++ b/RMuseum/Services/Implementation/ArtifactService.cs @@ -1166,6 +1166,27 @@ namespace RMuseum.Services.Implementation return new RServiceResult(res); } + /// + /// update artifact item + /// + /// + /// + public async Task> UpdateArtifactItemRecordAsync(RArtifactItemRecord item) + { + try + { + var dbItem = await _context.Items.Where(i => i.Id == item.Id).SingleAsync(); + _context.Entry(dbItem).CurrentValues.SetValues(item); + _context.Update(dbItem); + await _context.SaveChangesAsync(); + return new RServiceResult(true); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + ///