コード例 #1
0
        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" }));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
 public void AddEvento(Evento evento)
 {
     _context.Add(evento);
 }
コード例 #4
0
 public void Add <T>(T entity) where T : class
 {
     _context.Add(entity);
 }