Guest User

Untitled

a guest
Oct 20th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.48 KB | None | 0 0
  1. An unhandled exception has occurred while executing the request.
  2. System.InvalidOperationException: Unable to resolve service for type 'projetoweb.projetoContext' while attempting to activate 'projetoweb.Controllers.AnuncianteController'.
  3. at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
  4. at lambda_method(Closure , IServiceProvider , Object[] )
  5. at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass4_0.<CreateActivator>b__0(ControllerContext controllerContext)
  6. at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
  7. at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
  8. at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
  9. at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
  10. at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
  11. at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
  12. at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
  13. at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
  14. at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
  15. at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
  16. at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
  17. info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
  18. Request finished in 74.3081ms 500 text/html; charset=utf-8
  19.  
  20. using System;
  21. using Microsoft.EntityFrameworkCore;
  22. using Microsoft.EntityFrameworkCore.Metadata;
  23. using projetoweb.Models;
  24.  
  25. namespace projetoweb
  26. {
  27. public partial class projetoContext : DbContext
  28. {
  29. public DbSet<Anunciante> Anunciante { get; set; }
  30. public DbSet<Comprador> Comprador { get; set; }
  31. public DbSet<Pedido> Pedido { get; set; }
  32. public DbSet<Produto> Produto { get; set; }
  33. public DbSet<Promocao> Promocao { get; set; }
  34.  
  35. public projetoContext()
  36. {
  37. }
  38.  
  39. public projetoContext(DbContextOptions<projetoContext> options)
  40. : base(options)
  41. {
  42. }
  43.  
  44. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  45. {
  46. if (!optionsBuilder.IsConfigured)
  47. {
  48. optionsBuilder.UseMySql("Server=;Database=projeto;User=;Password=;");
  49. }
  50. }
  51.  
  52. protected override void OnModelCreating(ModelBuilder modelBuilder)
  53. {}
  54. }
  55. }
  56.  
  57. using System;
  58. using System.Collections.Generic;
  59. using System.Linq;
  60. using System.Threading.Tasks;
  61. using Microsoft.AspNetCore.Mvc;
  62. using Microsoft.AspNetCore.Mvc.Rendering;
  63. using Microsoft.EntityFrameworkCore;
  64. using projetoweb;
  65. using projetoweb.Models;
  66.  
  67. namespace projetoweb.Controllers
  68. {
  69. public class AnuncianteController : Controller
  70. {
  71. private readonly projetoContext _context;
  72.  
  73. public AnuncianteController(projetoContext context)
  74. {
  75. _context = context;
  76. }
  77.  
  78. // GET: Anunciante
  79. public async Task<IActionResult> Index()
  80. {
  81. return View(await _context.Anunciante.ToListAsync());
  82. }
  83.  
  84. // GET: Anunciante/Details/5
  85. public async Task<IActionResult> Details(int? id)
  86. {
  87. if (id == null)
  88. {
  89. return NotFound();
  90. }
  91.  
  92. var anunciante = await _context.Anunciante
  93. .FirstOrDefaultAsync(m => m.anu_id == id);
  94. if (anunciante == null)
  95. {
  96. return NotFound();
  97. }
  98.  
  99. return View(anunciante);
  100. }
  101.  
  102. // GET: Anunciante/Create
  103. public IActionResult Create()
  104. {
  105. return View();
  106. }
  107.  
  108. // POST: Anunciante/Create
  109. // To protect from overposting attacks, please enable the specific properties you want to bind to, for
  110. // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
  111. [HttpPost]
  112. [ValidateAntiForgeryToken]
  113. 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)
  114. {
  115. if (ModelState.IsValid)
  116. {
  117. _context.Add(anunciante);
  118. await _context.SaveChangesAsync();
  119. return RedirectToAction(nameof(Index));
  120. }
  121. return View(anunciante);
  122. }
  123.  
  124. // GET: Anunciante/Edit/5
  125. public async Task<IActionResult> Edit(int? id)
  126. {
  127. if (id == null)
  128. {
  129. return NotFound();
  130. }
  131.  
  132. var anunciante = await _context.Anunciante.FindAsync(id);
  133. if (anunciante == null)
  134. {
  135. return NotFound();
  136. }
  137. return View(anunciante);
  138. }
  139.  
  140. // POST: Anunciante/Edit/5
  141. // To protect from overposting attacks, please enable the specific properties you want to bind to, for
  142. // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
  143. [HttpPost]
  144. [ValidateAntiForgeryToken]
  145. 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)
  146. {
  147. if (id != anunciante.anu_id)
  148. {
  149. return NotFound();
  150. }
  151.  
  152. if (ModelState.IsValid)
  153. {
  154. try
  155. {
  156. _context.Update(anunciante);
  157. await _context.SaveChangesAsync();
  158. }
  159. catch (DbUpdateConcurrencyException)
  160. {
  161. if (!AnuncianteExists(anunciante.anu_id))
  162. {
  163. return NotFound();
  164. }
  165. else
  166. {
  167. throw;
  168. }
  169. }
  170. return RedirectToAction(nameof(Index));
  171. }
  172. return View(anunciante);
  173. }
  174.  
  175. // GET: Anunciante/Delete/5
  176. public async Task<IActionResult> Delete(int? id)
  177. {
  178. if (id == null)
  179. {
  180. return NotFound();
  181. }
  182.  
  183. var anunciante = await _context.Anunciante
  184. .FirstOrDefaultAsync(m => m.anu_id == id);
  185. if (anunciante == null)
  186. {
  187. return NotFound();
  188. }
  189.  
  190. return View(anunciante);
  191. }
  192.  
  193. // POST: Anunciante/Delete/5
  194. [HttpPost, ActionName("Delete")]
  195. [ValidateAntiForgeryToken]
  196. public async Task<IActionResult> DeleteConfirmed(int id)
  197. {
  198. var anunciante = await _context.Anunciante.FindAsync(id);
  199. _context.Anunciante.Remove(anunciante);
  200. await _context.SaveChangesAsync();
  201. return RedirectToAction(nameof(Index));
  202. }
  203.  
  204. private bool AnuncianteExists(int id)
  205. {
  206. return _context.Anunciante.Any(e => e.anu_id == id);
  207. }
  208. }
  209. }
Add Comment
Please, Sign In to add comment