public async Task <IActionResult> NuevoAsync(string inputNombre, string inputInicio, string inputFinal, IFormFile inputImagen) { EventoContext context = HttpContext.RequestServices.GetService(typeof(EventoContext)) as EventoContext; if (inputImagen == null || inputImagen.Length == 0) { return(Content("file not selected")); } var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\", inputImagen.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await inputImagen.CopyToAsync(stream); } string filePath = inputImagen.FileName; bool result = context.Add(inputNombre, inputInicio, inputFinal, filePath); if (result) { return(RedirectToAction("Nuevo", "Evento", new { result = "Success" })); } return(RedirectToAction("Nuevo", "Evento", new { result = "Failure" })); }
public async Task <IActionResult> Create([Bind("Id,Nome,Valor,Gratuito,Descricao,Data")] Evento evento) { if (ModelState.IsValid) { evento.Id = Guid.NewGuid(); _context.Add(evento); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(evento)); }
public void AddEvento(Evento evento) { _context.Add(evento); }
public void Add <T>(T entity) where T : class { _context.Add(entity); }