1-) .Net Core Web Api - GraphQL gibi columnları güncellemek
[HttpPost]
[Route("update")]
public IActionResult update(Files file)
{
if (file == null)
return NotFound();
}
if (file.id < 1)
return Ok("Lütfen id gönderin");
using var context = new Context();
var existingFile = context.Files.Find(file.id);
if (existingFile == null)
foreach (var property in typeof(Files).GetProperties())
var newValue = property.GetValue(file);
var oldValue = property.GetValue(existingFile);
// Sadece yeni gelen değer null değilse ve eski değerinden farklıysa güncelle
if (newValue != null && !newValue.Equals(oldValue))
property.SetValue(existingFile, newValue);
context.SaveChanges();
return Ok(existingFile);