public async Task <IActionResult> Edit(int id, [Bind("Id,Soz")] GuzelSoz guzelSoz) { if (id != guzelSoz.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(guzelSoz); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GuzelSozExists(guzelSoz.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(guzelSoz)); }
public async Task <IActionResult> Create([Bind("Id,Soz")] GuzelSoz guzelSoz) { if (ModelState.IsValid) { _context.Add(guzelSoz); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(guzelSoz)); }
//https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-5.0#walkthrough-creating-a-simple-view-component public async Task <IViewComponentResult> InvokeAsync(bool enYeniyiGoster = false) { if (enYeniyiGoster) { return(View(await _db.GuzelSozler.OrderBy(x => x.Id).LastOrDefaultAsync())); } var adet = _db.GuzelSozler.Count(); int indeks = new Random().Next(adet); GuzelSoz soz = await _db.GuzelSozler.Skip(indeks).FirstOrDefaultAsync(); return(View(soz)); }