Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("IDRefeicoesRestaurante,Nome,Quantidade,IDRestaurante")] RefeicoesRestaurante refeicoesRestaurante)
        {
            if (id != refeicoesRestaurante.IDRefeicoesRestaurante)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(refeicoesRestaurante);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RefeicoesRestauranteExists(refeicoesRestaurante.IDRefeicoesRestaurante))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IDRestaurante"] = new SelectList(_context.Restaurante, "IDRestaurante", "Nome", refeicoesRestaurante.IDRestaurante);
            return(View(refeicoesRestaurante));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("IDVoluntarios,Nome,Telefone,Email,Morada,DataNasc,NrTotalEntregas")] Voluntarios voluntarios)
        {
            var email        = voluntarios.Email;
            var morada       = voluntarios.Morada;
            var telefone     = voluntarios.Telefone;
            var idVoluntario = voluntarios.IDVoluntarios;


            if (id != voluntarios.IDVoluntarios)
            {
                return(NotFound());
            }

            //Validar Email
            if (emailrepetidoEditar(email, idVoluntario) == true)
            {
                //Mensagem de erro se o email for repetido
                ModelState.AddModelError("Email", "Este email já existe");
            }

            //Validar morada
            if (moradarepetidaEditar(morada, idVoluntario) == true)
            {
                //Mensagem de erro se a morada ja existir noutro registo
                ModelState.AddModelError("Morada", "Esta morada já foi utilizada");
            }
            //Validar Contacto
            if (contactorepetidoEditar(telefone, idVoluntario))
            {
                //Mensagem de erro se o contacto ja existe
                ModelState.AddModelError("Telefone", "Contacto já utilizado");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (!emailrepetidoEditar(email, idVoluntario) || moradarepetidaEditar(morada, idVoluntario) || contactorepetidoEditar(telefone, idVoluntario))
                    {
                        _context.Update(voluntarios);
                        await _context.SaveChangesAsync();

                        TempData["successEdit"] = "Registo alterado com sucesso";
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VoluntariosExists(voluntarios.IDVoluntarios))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(voluntarios));
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("IDTipo,Nome")] Tipo tipo)
        {
            if (id != tipo.IDTipo)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tipo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TipoExists(tipo.IDTipo))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipo));
        }
Пример #4
0
        public async Task <IActionResult> Edit(int id, [Bind("RegrasID,Nome,Rendimento,Agregado,Pedidos,Alimentos")] Regras regras)
        {
            if (id != regras.RegrasID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(regras);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RegrasExists(regras.RegrasID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(regras));
        }
Пример #5
0
        public async Task <IActionResult> Edit(int id, [Bind("IDProdutosSupermercado,Nome,Quantidade,IDSupermercado,IDTipo")] ProdutosSupermercado produtosSupermercado)
        {
            if (id != produtosSupermercado.IDProdutosSupermercado)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(produtosSupermercado);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProdutosSupermercadoExists(produtosSupermercado.IDProdutosSupermercado))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IDSupermercado"] = new SelectList(_context.Supermercado, "IDSupermercado", "Email", produtosSupermercado.IDSupermercado);
            ViewData["IDTipo"]         = new SelectList(_context.Tipo, "IDTipo", "Nome", produtosSupermercado.IDTipo);
            return(View(produtosSupermercado));
        }
Пример #6
0
        public async Task <IActionResult> Edit(int id, [Bind("IDPedidoSupermercado,Quantidade,EstadoEntrega,DataEntrega,IDFamilias,IDInstituicoes,IDProdutosSupermercado,IDVoluntarios")] PedidoSupermercado pedidoSupermercado)
        {
            if (id != pedidoSupermercado.IDPedidoSupermercado)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pedidoSupermercado);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PedidoSupermercadoExists(pedidoSupermercado.IDPedidoSupermercado))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IDFamilias"]             = new SelectList(_context.Familias, "IDFamilias", "Email", pedidoSupermercado.IDFamilias);
            ViewData["IDInstituicoes"]         = new SelectList(_context.Instituicoes, "IDInstituicoes", "Email", pedidoSupermercado.IDInstituicoes);
            ViewData["IDProdutosSupermercado"] = new SelectList(_context.ProdutosSupermercado, "IDProdutosSupermercado", "Nome", pedidoSupermercado.IDProdutosSupermercado);
            ViewData["IDVoluntarios"]          = new SelectList(_context.Voluntarios, "IDVoluntarios", "Email", pedidoSupermercado.IDVoluntarios);
            return(View(pedidoSupermercado));
        }
Пример #7
0
        public async Task <IActionResult> Edit(int id, [Bind("IDTipo,Nome")] Tipo tipo)
        {
            var nome   = tipo.Nome;
            var idTipo = tipo.IDTipo;

            if (id != tipo.IDTipo)
            {
                return(NotFound());
            }
            //Validar tipo
            if (tiporepetidoEditar(nome, idTipo) == true)
            {
                //Mensagem de erro se o tipo for repetido
                ModelState.AddModelError("Nome", "Este Tipo já existe");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (!tiporepetidoEditar(nome, idTipo))
                    {
                        _context.Update(tipo);
                        await _context.SaveChangesAsync();

                        TempData["successEdit"] = "Registo alterado com sucesso";
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TipoExists(tipo.IDTipo))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipo));
        }