How to create one function “HeroesUpdate” in a cs file

  Kiến thức lập trình

In the “HeroController.cs” API Controller you need to do the following [23 Marks]
o Create the “HeroesUpdate” public Put endpoint/function to allow Heroes to be fetched from the
GetHeroesByFilterAsync repository function. In addition, the user should be able to update records by
replacing an existing string value with a new string value. Note: The endpoint/function route name should
be the same as the endpoint/function name. Furthermore, the endpoint/function is an asynchronous
INF354 – 2024 © UP: SEMESTER TEST 1 3 / 7
endpoint/method taking two “strings” as parameters (existing and new string values) and returning an
“IActionResult” (8 marks).
o Therefore, you need to get the existing Heroes data from the “GetHeroesByFilterAsync” function by
passing the existing search string value as a parameter within a try/catch block (3 marks).
o If records are returned from the “GetHeroesByFilterAsync” function call that contains the existing search
string value, you must replace the existing string value from any of the string properties in the Hero model.
In other words, replace the existing string value with the new string value wherever it is found in any of the
varchar Columns. For example, if the text in the Name column reads “Bruce Banner (The Hulk)” and
your existing string value is “Bruce” and the new string value is “Peanut”, then the new text in the Name
column, after update, should read “Peanut Banner (The Hulk)”. This functionality should happen across
the Columns of the table and across the Records. In other words, it should update multiple columns and
records that matches the existing value simultaneously (9 marks).
o After the successful Update, the endpoint/function must return a 200 (Ok) response with the text “The
heroes have been updated successfully” (1 mark).
o If no records exist that contains that existing search string value, the endpoint/function must return a
NotFound response with the returned text “Heroes with the text existingValue does not exist”. With
“existingValue” being the text, you passed to the Endpoint (1 mark).
o If any Exceptions happen it should be caught in the catch block and a 500 (InternalServerError)
response with the message “An unexpected problem occurred. Please create a support ticket.” should be
returned (1 mark).

[Httpput]
[Route(“UpdateHero/(HeroID)”)]
public async TaskHeroUpdate(string filter, HeroViewModel herovimodel)
{
try
{
var excistingHero
}
}

[Httpput]
[Route(“UpdateHero/(HeroID)”)]
public async TaskHeroUpdate(string filter, HeroViewModel herovimodel)
{
try
{
var excistingHero
}
}

New contributor

Callum_10 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

LEAVE A COMMENT