Exemplo n.º 1
0
        public async Task <IActionResult> Inserir(InserirEditar.Command request)
        {
            try
            {
                if (request.Imagem != null)
                {
                    var uniqueFileName = GetUniqueFileName(request.Imagem.FileName);
                    var uploads        = Path.Combine(hostingEnvironment.WebRootPath, "uploads");
                    var filePath       = Path.Combine(uploads, uniqueFileName);
                    request.Imagem.CopyTo(new FileStream(filePath, FileMode.Create));

                    //to do : Save uniqueFileName  to your db table
                }

                await _mediator.Send(request);

                return(RedirectToAction("Index", new { cache = DateTime.Now.Ticks }));
            }
            catch (Exception ex)
            {
                if (!ModelState.AdicionarErrosDeValidacao(ex))
                {
                    throw;
                }
            }

            return(View(nameof(InserirEditar), request));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Editar(InserirEditar.Command request)
        {
            try
            {
                await _mediator.Send(request);

                return(RedirectToAction("Index", new { cache = DateTime.Now.Ticks }));
            }
            catch (Exception ex)
            {
                if (!ModelState.AdicionarErrosDeValidacao(ex))
                {
                    throw;
                }
            }

            return(View(nameof(InserirEditar), request));
        }