I am new to ASP.NET Core MVC. I have to make a project in which multiple user accounts creates and each user creates his own Todo with CRUD operation. Each user should be able to see his/her own Todo listing page.
For this, I used identity framework. I did this work until now
How to add tables and relations to generated ASP.NET Core MVC Identity database?
My code shows all Todo listing in every user login. Please guide me how each user see and operate his own Todo.
This is my code:
public async Task<IActionResult> Index()
{
return View(await _context.Activitiess.ToListAsync());
}
[Authorize]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Description")] Activities activities)
{
if (ModelState.IsValid)
{
_context.Add(activities);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(activities);
}
[Authorize]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("Id,Description")] Activities activities)
{
if (id != activities.Id)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
_context.Update(activities);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ActivitiesExists(activities.Id))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
return View(activities);
}