Ir ao conteúdo
  • Cadastre-se

Outro Retornar o valor medio de uma variavel na models e adicionar no controoler


Posts recomendados

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Prova.Models;

namespace Prova.Controllers
{
    public class FilmeController : Controller
    {
        private readonly Context _context;

        public FilmeController(Context context)
        {
            _context = context;
        }

        // GET: Time
        public async Task<IActionResult> Index(string pesquisa)
        {
            var filmes = from m in _context.Filme
                        select m;

            if (!String.IsNullOrEmpty(pesquisa))
            {
                filmes = filmes.Where(s => s.Titulo.Contains(pesquisa));
            }
                var result = await filmes.ToListAsync();
                return View(result);

        }      

        public async Task<IActionResult> Reviews(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            var filmes = await _context.Filme
                .FirstOrDefaultAsync(m => m.FilmeID == id);
            if (filmes == null)
            {
                return NotFound();
            }

            return View(filmes);
        }


public async Task<IActionResult> About(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            var filmes = await _context.Filme
                .FirstOrDefaultAsync(m => m.FilmeID == id);
            if (filmes == null)
            {
                return NotFound();
            }

            return View(filmes);
        }

  // GET: Time/Create
        public IActionResult Create()
        {
            return View();
        }

        // POST: Time/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> Create([Bind("FilmeID,Titulo,Diretor,DataLanc,Genero,Faixa_Etaria")] Filme filme)
        {
            if (ModelState.IsValid)
            {
                _context.Add(filme);
                await _context.SaveChangesAsync();
                return RedirectToAction(nameof(Index));
            }
            return View(filme);
        }

        // GET: Time/Edit/5
        public async Task<IActionResult> Edit(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            var filme = await _context.Filme.FindAsync(id);
            if (filme == null)
            {
                return NotFound();
            }
            return View(filme);
        }

        // POST: Time/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> Edit(int id, [Bind("FilmeID,Titulo,Diretor, DataLanc,Genero,Faixa_Etaria")] Filme filme)
        {
            if (id != filme.FilmeID)
            {
                return NotFound();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(filme);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TimeExists(filme.FilmeID))
                    {
                        return NotFound();
                    }
                    else
                    {
                        throw;
                    }
                }
                return RedirectToAction(nameof(Index));
            }
            return View(filme);
        }

        // GET: Time/Delete/5
        public async Task<IActionResult> Delete(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            var filme = await _context.Filme
                .FirstOrDefaultAsync(m => m.FilmeID == id);
            if (filme == null)
            {
                return NotFound();
            }

            return View(filme);
        }

        // POST: Time/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> DeleteConfirmed(int id)
        {
            var filme = await _context.Filme.FindAsync(id);
            _context.Filme.Remove(filme);
            await _context.SaveChangesAsync();
            return RedirectToAction(nameof(Index));
        }

        private bool TimeExists(int id)
        {
            return _context.Filme.Any(e => e.FilmeID == id);
        }




    }



}

Boa noite. gostaria de saber como eu faço para que eu retorne uma nota máxima de um review de um filme e exibir as 5 maiores notas na homepage em c# em uma aplicação dotnet core. Já adicionei na models a variável que ira armazenar essa nota, agora preciso coloca-la no controller e exibir na pagina inicial

Segue o código do controller

Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...