Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- An unhandled exception has occurred while executing the request.
- System.InvalidOperationException: Unable to resolve service for type 'projetoweb.projetoContext' while attempting to activate 'projetoweb.Controllers.AnuncianteController'.
- at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
- at lambda_method(Closure , IServiceProvider , Object[] )
- at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass4_0.<CreateActivator>b__0(ControllerContext controllerContext)
- at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
- at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
- at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
- at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
- at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
- at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
- at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
- at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
- at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
- at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
- at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
- info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
- Request finished in 74.3081ms 500 text/html; charset=utf-8
- using System;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.EntityFrameworkCore.Metadata;
- using projetoweb.Models;
- namespace projetoweb
- {
- public partial class projetoContext : DbContext
- {
- public DbSet<Anunciante> Anunciante { get; set; }
- public DbSet<Comprador> Comprador { get; set; }
- public DbSet<Pedido> Pedido { get; set; }
- public DbSet<Produto> Produto { get; set; }
- public DbSet<Promocao> Promocao { get; set; }
- public projetoContext()
- {
- }
- public projetoContext(DbContextOptions<projetoContext> options)
- : base(options)
- {
- }
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- {
- if (!optionsBuilder.IsConfigured)
- {
- optionsBuilder.UseMySql("Server=;Database=projeto;User=;Password=;");
- }
- }
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {}
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.Rendering;
- using Microsoft.EntityFrameworkCore;
- using projetoweb;
- using projetoweb.Models;
- namespace projetoweb.Controllers
- {
- public class AnuncianteController : Controller
- {
- private readonly projetoContext _context;
- public AnuncianteController(projetoContext context)
- {
- _context = context;
- }
- // GET: Anunciante
- public async Task<IActionResult> Index()
- {
- return View(await _context.Anunciante.ToListAsync());
- }
- // GET: Anunciante/Details/5
- public async Task<IActionResult> Details(int? id)
- {
- if (id == null)
- {
- return NotFound();
- }
- var anunciante = await _context.Anunciante
- .FirstOrDefaultAsync(m => m.anu_id == id);
- if (anunciante == null)
- {
- return NotFound();
- }
- return View(anunciante);
- }
- // GET: Anunciante/Create
- public IActionResult Create()
- {
- return View();
- }
- // POST: Anunciante/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("anu_id,anu_nome,anu_cpnj,anu_senha,anu_rua,anu_bairro,anu_cidade,anu_estado,anu_plano_atual,anu_qtd_anuncios,anu_qtd_anuncios_relevantes,anu_data_cadastro,anu_imagem")] Anunciante anunciante)
- {
- if (ModelState.IsValid)
- {
- _context.Add(anunciante);
- await _context.SaveChangesAsync();
- return RedirectToAction(nameof(Index));
- }
- return View(anunciante);
- }
- // GET: Anunciante/Edit/5
- public async Task<IActionResult> Edit(int? id)
- {
- if (id == null)
- {
- return NotFound();
- }
- var anunciante = await _context.Anunciante.FindAsync(id);
- if (anunciante == null)
- {
- return NotFound();
- }
- return View(anunciante);
- }
- // POST: Anunciante/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("anu_id,anu_nome,anu_cpnj,anu_senha,anu_rua,anu_bairro,anu_cidade,anu_estado,anu_plano_atual,anu_qtd_anuncios,anu_qtd_anuncios_relevantes,anu_data_cadastro,anu_imagem")] Anunciante anunciante)
- {
- if (id != anunciante.anu_id)
- {
- return NotFound();
- }
- if (ModelState.IsValid)
- {
- try
- {
- _context.Update(anunciante);
- await _context.SaveChangesAsync();
- }
- catch (DbUpdateConcurrencyException)
- {
- if (!AnuncianteExists(anunciante.anu_id))
- {
- return NotFound();
- }
- else
- {
- throw;
- }
- }
- return RedirectToAction(nameof(Index));
- }
- return View(anunciante);
- }
- // GET: Anunciante/Delete/5
- public async Task<IActionResult> Delete(int? id)
- {
- if (id == null)
- {
- return NotFound();
- }
- var anunciante = await _context.Anunciante
- .FirstOrDefaultAsync(m => m.anu_id == id);
- if (anunciante == null)
- {
- return NotFound();
- }
- return View(anunciante);
- }
- // POST: Anunciante/Delete/5
- [HttpPost, ActionName("Delete")]
- [ValidateAntiForgeryToken]
- public async Task<IActionResult> DeleteConfirmed(int id)
- {
- var anunciante = await _context.Anunciante.FindAsync(id);
- _context.Anunciante.Remove(anunciante);
- await _context.SaveChangesAsync();
- return RedirectToAction(nameof(Index));
- }
- private bool AnuncianteExists(int id)
- {
- return _context.Anunciante.Any(e => e.anu_id == id);
- }
- }
- }
Add Comment
Please, Sign In to add comment