DELETE-endpoint: 'Avada Kedavra' to movie!

Co-authored-by: haraldnilsen <harald_998@hotmail.com>
This commit is contained in:
Sindre Kjelsrud 2023-09-26 10:13:32 +02:00
parent a134a5e376
commit 4461c9838f

View file

@ -102,4 +102,26 @@ public class MovieController: ControllerBase
return StatusCode(500, "Internal server error");
}
}
[HttpDelete(Name = "DeleteMovie")]
public ActionResult Delete([FromQuery] string imdbID) {
try
{
var movie = _context.Movies.AsEnumerable()
.Where(m => m.imdbID.ToLower().Contains(imdbID.ToLower()))
.ElementAtOrDefault(0);
if (movie != null) {
_context.Remove(movie);
_context.SaveChanges();
return Ok("Successfully deleted movie");
} else {
return StatusCode(409, "Conflict, imdbID doesn't exists");
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error deleting movie");
return StatusCode(500, "Internal server error");
}
}
}