コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        //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));
        }