Hello All,
I am working on asp core with entity framework. i want to insert record if not a single record exists else update record
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(InstitutionDetails schooldetails)
{
if (ModelState.IsValid)
{
var details = db.InstitutionDetails.FirstOrDefault();
var files = HttpContext.Request.Form.Files;
if (details == null)
{
db.Add(schooldetails);
await db.SaveChangesAsync();
}
else
{
db.Update(schooldetails);
await db.SaveChangesAsync();
}
return RedirectToAction("institution");
}
else
{
var errors = ModelState.Values.SelectMany(v => v.Errors);
}
return View(schooldetails);
}
In Given code snipet it save new record everytime.
Please help me anyone