예제 #1
0
        public async Task <IActionResult> EditPersonalData(EditLoggedInCustomerViewModel customer)
        {
            if (!ModelState.IsValid)
            {
                return(View(customer));
            }

            string email = User.Identity.Name;

            var customerLoggedin = await _context.Customer.SingleOrDefaultAsync(c => c.Email == email);

            if (customerLoggedin == null)
            {
                return(NotFound());
            }

            customerLoggedin.Name = customer.Name;

            try
            {
                _context.Update(customerLoggedin);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //todo: show error message

                throw;
            }
            return(RedirectToAction(nameof(Index), "Home"));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("LocalidadeId,NomeLocalidade,Descricao,Populacao")] Localidade localidade)
        {
            if (id != localidade.LocalidadeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(localidade);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LocalidadeExists(localidade.LocalidadeId))
                    {
                        ViewBag.Message = "Esta localidade foi eliminada, pode inserir outra com as mesmas informações";
                        return(View("ViewINSUCESSO"));
                    }
                    else
                    {
                        ViewBag.Message = "Esta localidade talvez tenha eliminada, tente novamente.";
                        return(View("ViewINSUCESSO"));

                        throw;
                    }
                }
                ViewBag.Message = "Esta localidade foi editada com sucesso";
                return(View("ViewSUCESSO"));
            }
            return(View(localidade));
        }
        public async Task <IActionResult> Edit(int id, [Bind("OrganizadorId,NomeOrganizador,Contacto,DataNascimento,EmailAddress")] Organizador organizador)
        {
            if (id != organizador.OrganizadorId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(organizador);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrganizadorExists(organizador.OrganizadorId))
                    {
                        ViewBag.Message = "Este organizador foi eliminado, pode inserir outro com as mesmas informações";
                        return(View("ViewINSUCESSO"));
                    }
                    else
                    {
                        ViewBag.Message = "Este organizador talvez tenha eliminado, tente novamente.";
                        return(View("ViewINSUCESSO"));

                        throw;
                    }
                }
                ViewBag.Message = "Este organizador foi editado com sucesso";
                return(View("ViewSUCESSO"));
            }
            return(View(organizador));
        }
        public async Task <IActionResult> Edit(int id, [Bind("TipoEventosId,NomeTipoEventos")] TipoEventos tipoEventos)
        {
            if (id != tipoEventos.TipoEventosId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tipoEventos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TipoEventosExists(tipoEventos.TipoEventosId))
                    {
                        ViewBag.Message = "Este tipo de evento foi eliminado, pode inserir outro com as mesmas informações";
                        return(View("ViewINSUCESSO"));
                    }
                    else
                    {
                        ViewBag.Message = "Este tipo de evento talvez tenha eliminado, tente novamente.";
                        return(View("ViewINSUCESSO"));

                        throw;
                    }
                }
                ViewBag.Message = "Este tipo de evento foi editado com sucesso";
                return(View("ViewSUCESSO"));
            }
            return(View(tipoEventos));
        }
예제 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("EventosId,NomeEventos,Descricao,Lotacao,DataRealizacao,HoraRealizacao,LocalidadeId,TipoEventosId,OrganizadorId")] Eventos eventos)
        {
            if (id != eventos.EventosId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(eventos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EventosExists(eventos.EventosId))
                    {
                        ViewBag.Message = "Este evento foi eliminado, pode inserir outro com as mesmas informações";
                        return(View("ViewINSUCESSO"));
                    }
                    else
                    {
                        ViewBag.Message = "Este evento talvez tenha eliminado, tente novamente.";
                        return(View("ViewINSUCESSO"));

                        throw;
                    }
                }
                ViewBag.Message = "Este evento foi editado com sucesso";
                return(View("ViewSUCESSO"));
            }
            ViewData["LocalidadeId"]  = new SelectList(_context.Localidade, "LocalidadeId", "NomeLocalidade", eventos.LocalidadeId);
            ViewData["OrganizadorId"] = new SelectList(_context.Organizador, "OrganizadorId", "NomeOrganizador", eventos.OrganizadorId);
            ViewData["TipoEventosId"] = new SelectList(_context.TiposEventos, "TipoEventosId", "NomeTipoEventos", eventos.TipoEventosId);
            return(View(eventos));
        }