public async Task <ActionResult> Registrar(UsuarioRegistrado usuarioRegistro)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            var user = new IdentityUser
            {
                UserName       = usuarioRegistro.Email,
                Email          = usuarioRegistro.Email,
                EmailConfirmed = true
            };

            var result = await _userManager.CreateAsync(user, usuarioRegistro.Senha);

            if (result.Succeeded)
            {
                return(CustomResponse(await GerarJwt(usuarioRegistro.Email)));
            }

            foreach (var error in result.Errors)
            {
                AdicionarErroProcessamento(error.Description);
            }

            return(CustomResponse());
        }
示例#2
0
    protected void lbtnRealizarPedido_Click(object sender, EventArgs e)
    {
        try
        {
            List <LineaPedido> lineasDePedido = (List <LineaPedido>)Session["CarritoLineaPedido"];

            if (lineasDePedido != null)
            {
                int numeroPedido = (int)Application["NumeroPedido"] + 1;;

                Application["NumeroPedido"] = numeroPedido;

                DateTime fechaPedido = DateTime.Today;

                double precioTotal = 0;

                foreach (LineaPedido lp in lineasDePedido)
                {
                    precioTotal += lp.Cantidad * lp.PArticulo.Precio;
                }

                bool enviado = false;

                UsuarioRegistrado registrado = (UsuarioRegistrado)Session["Usuario"];

                Pedido pedidoUsuario = new Pedido(numeroPedido, fechaPedido, precioTotal, enviado, registrado, lineasDePedido);

                List <Pedido> pedidosSolicitados = (List <Pedido>)Application["PedidoSolicitados"];

                pedidosSolicitados.Add(pedidoUsuario);

                Application["PedidoSolicitados"] = pedidosSolicitados;
                Session.Remove("CarritoLineaPedido");
                lblMensaje.ForeColor = System.Drawing.Color.Green;
                lblMensaje.Text      = "¡Pedido Realizado con Exito!";
                _realizarPedido      = true;
            }
            else
            {
                _realizarPedido      = false;
                lblMensaje.ForeColor = System.Drawing.Color.Red;
                lblMensaje.Text      = "El carrito esta vacio.";
            }
        }
        catch (ApplicationException ex)
        {
            lblMensaje.ForeColor = System.Drawing.Color.Red;
            lblMensaje.Text      = "¡Error! " + ex.Message;
        }

        catch
        {
            lblMensaje.ForeColor = System.Drawing.Color.Red;
            lblMensaje.Text      = "¡Error! Al cargar la pagina.";
        }
    }
        public static UsuarioRegistrado Buscar(int cedula, bool busqueda)
        {
            SqlConnection conexion     = null;
            SqlDataReader drRegistrado = null;

            try
            {
                conexion = new SqlConnection(Conexion.CadenaConexion);

                if (busqueda)
                {
                    SqlCommand cmdBuscarRegistrado = new SqlCommand("BuscarUsuarioRegistrado", conexion);
                    cmdBuscarRegistrado.CommandType = CommandType.StoredProcedure;

                    cmdBuscarRegistrado.Parameters.AddWithValue("@cedula", cedula);

                    conexion.Open();

                    drRegistrado = cmdBuscarRegistrado.ExecuteReader();
                }
                else
                {
                    SqlCommand cmdBuscarRegistrado = new SqlCommand("BuscarUsuarioRegistradoEliminadoLogica", conexion);
                    cmdBuscarRegistrado.CommandType = CommandType.StoredProcedure;

                    cmdBuscarRegistrado.Parameters.AddWithValue("@cedula", cedula);

                    conexion.Open();

                    drRegistrado = cmdBuscarRegistrado.ExecuteReader();
                }

                UsuarioRegistrado registrado = null;

                if (drRegistrado.Read())
                {
                    registrado = new UsuarioRegistrado((int)drRegistrado["Cedula"], (string)drRegistrado["NombreCompleto"], (string)drRegistrado["NombreUsuario"], (string)drRegistrado["Contrasenia"], (string)drRegistrado["Imagen"], (string)drRegistrado["DireccionEnvio"], (long)drRegistrado["NumeroTarjeta"], (int)drRegistrado["Telefono"], (bool)drRegistrado["Eliminado"]);
                }

                return(registrado);
            }

            finally
            {
                if (drRegistrado != null)
                {
                    drRegistrado.Close();
                }

                if (conexion != null)
                {
                    conexion.Close();
                }
            }
        }
示例#4
0
 private void Login_usuario()
 {
     try
     {
         usuarioRegistrado = new UsuarioRegistrado(baseDeDatos, new LogMySQL(baseDeDatos));
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public static List <UsuarioRegistrado> Listar()
        {
            SqlConnection conexion     = null;
            SqlDataReader drRegistrado = null;

            try
            {
                conexion = new SqlConnection(Conexion.CadenaConexion);

                SqlCommand cmdListarRegistrados = new SqlCommand("ListarRegistrados", conexion);
                cmdListarRegistrados.CommandType = CommandType.StoredProcedure;

                conexion.Open();

                drRegistrado = cmdListarRegistrados.ExecuteReader();

                List <UsuarioRegistrado> registrados = new List <UsuarioRegistrado>();
                UsuarioRegistrado        registrado;

                while (drRegistrado.Read())
                {
                    registrado = new UsuarioRegistrado((int)drRegistrado["Cedula"], (string)drRegistrado["NombreCompleto"], (string)drRegistrado["NombreUsuario"], (string)drRegistrado["Contrasenia"], (string)drRegistrado["Imagen"], (string)drRegistrado["DireccionEnvio"], (long)drRegistrado["NumeroTarjeta"], (int)drRegistrado["Telefono"], (bool)drRegistrado["Eliminado"]);

                    registrados.Add(registrado);
                }

                return(registrados);
            }
            finally
            {
                if (drRegistrado != null)
                {
                    drRegistrado.Close();
                }

                if (conexion != null)
                {
                    conexion.Close();
                }
            }
        }
    protected void btnSolicitarPedido_Click(object sender, EventArgs e)
    {
        if (Session["Usuario"] != null)
        {
            try
            {
                List <LineaPedido> lineasDePedido = (List <LineaPedido>)Session["CarritoLineaPedido"];

                if (lineasDePedido != null)
                {
                    int numeroPedido = 1;

                    DateTime fechaPedido = DateTime.Today;

                    double precioTotal = 0;

                    foreach (LineaPedido lp in lineasDePedido)
                    {
                        precioTotal += lp.Cantidad * lp.PArticulo.Precio;
                    }

                    bool enviado = false;

                    UsuarioRegistrado registrado = (UsuarioRegistrado)Session["Usuario"];

                    Pedido pedidoUsuario = new Pedido(numeroPedido, fechaPedido, precioTotal, enviado, registrado, lineasDePedido);

                    LogicaPedido.AgregarPedido(pedidoUsuario);

                    Session.Remove("CarritoLineaPedido");

                    Panel1.Visible             = true;
                    btnEliminarPedido.Visible  = false;
                    btnSolicitarPedido.Visible = false;

                    lblMensaje.ForeColor = System.Drawing.Color.Green;
                    lblMensaje.Text      = "¡Pedido generado exitosamente!.";

                    //esto es una prueba
                    //string aa = ((UserControl)this.Master.Controls[2]).ID;
                    //((Label)((UserControl)this.Master.Controls[2]).Controls[2]).Text = precioTotal;
                }
                else
                {
                    gvCarrito.Visible = false;
                    throw new ExcepcionPresentacion("Usted ya solicito este pedido.");
                }
            }
            catch (ApplicationException ex)
            {
                lblMensaje.ForeColor = System.Drawing.Color.Red;
                lblMensaje.Text      = "¡Error! " + ex.Message;
            }

            catch
            {
                lblMensaje.ForeColor = System.Drawing.Color.Red;
                lblMensaje.Text      = "¡Error! Al generar el pedido.";
            }
        }
        else
        {
            lblMensaje.ForeColor = System.Drawing.Color.Red;
            lblMensaje.Text      = "¡Error! Para realizar un pedido debe estar registrado, comuniquese con el administrador para registrarse.";
        }
    }
示例#7
0
 public List <UsuarioRegistrado> Filtrar(UsuarioRegistrado registroGuardos)
 {
     throw new NotImplementedException();
 }
    protected void imgbtnAgregar_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            int cedula;

            try
            {
                cedula = Convert.ToInt32(txtCedula.Text);
            }
            catch
            {
                throw new ExcepcionPresentacion("Ingrese una cédula válida, sin puntos ni guiones");
            }

            string nombreCompleto = null;

            if (txtNombreCompleto.Text != String.Empty)
            {
                nombreCompleto = txtNombreCompleto.Text;
            }

            string nombreUsuario = null;

            if (txtNombreUsuario.Text != String.Empty)
            {
                nombreUsuario = txtNombreUsuario.Text;
            }

            string contrasenia = null;

            if (txtContrasenia.Text != txtConfirmacion.Text)
            {
                throw new ExcepcionPresentacion("Las contraseñas no coinciden");
            }

            if (txtContrasenia.Text != String.Empty)
            {
                contrasenia = txtContrasenia.Text;
            }

            string direccion = null;

            if (txtDireccion.Text != String.Empty)
            {
                direccion = txtDireccion.Text;
            }

            long numeroTarjeta;

            try
            {
                numeroTarjeta = Convert.ToInt64(txtNroTarjeta.Text);
            }
            catch
            {
                throw new ExcepcionPresentacion("Ingrese número de tarjeta válido");
            }

            int telefono;

            try
            {
                telefono = Convert.ToInt32(txtTelefono.Text);
            }
            catch
            {
                throw new ExcepcionPresentacion("Ingrese número de teléfono válido");
            }
            string imagen = imgAvatar.ImageUrl;

            if (subirImagen.HasFile)
            {
                imagen = "~/uploads/usuarios/" + nombreUsuario + ".jpg";
            }

            bool Eliminado = false;


            try
            {
                if (subirImagen.HasFile)
                {
                    string imagenLocal = subirImagen.PostedFile.FileName;

                    string extension = imagenLocal.Substring(imagenLocal.Length - 4, 4);

                    if (extension.ToLower() != ".jpg" && extension.ToLower() != ".png" && extension.ToLower() != ".gif" && extension.ToLower() != ".jpeg")
                    {
                        throw new ExcepcionPresentacion("Formato de imagen no válido");
                    }

                    string imagenServidor = Server.MapPath("~/uploads/usuarios/") + nombreUsuario + ".jpg";

                    System.IO.File.Copy(imagenLocal, imagenServidor, true);
                }
            }

            catch (ApplicationException ex)
            {
                throw ex;
            }
            catch
            {
                throw new ExcepcionPresentacion("No se pudo subir el archivo.");
            }

            UsuarioRegistrado registrado = new UsuarioRegistrado(cedula, nombreCompleto, nombreUsuario, contrasenia, imagen, direccion, numeroTarjeta, telefono, Eliminado);

            UsuarioRegistrado registradoEliminado = (UsuarioRegistrado)LogicaUsuario.Buscar(cedula, false);

            if (registradoEliminado != null)
            {
                LogicaUsuario.Modificar(registrado);
            }
            else
            {
                LogicaUsuario.Agregar(registrado);
            }

            LimpiarFormulario();

            lblMensaje.ForeColor = System.Drawing.Color.Green;
            lblMensaje.CssClass  = "labelok";
            lblMensaje.Text      = "Usuario Agregado con éxito";
        }

        catch (ApplicationException ex)
        {
            lblMensaje.ForeColor = System.Drawing.Color.Red;
            lblMensaje.CssClass  = "labelerror";
            lblMensaje.Text      = "¡ERROR! " + ex.Message + ".";
        }

        catch
        {
            lblMensaje.ForeColor = System.Drawing.Color.Red;
            lblMensaje.CssClass  = "labelerror";
            lblMensaje.Text      = "Se produjo un error al agregar el usuario.";
        }
    }
        public static void Eliminar(UsuarioRegistrado registrado)
        {
            SqlConnection conexion = null;

            try
            {
                conexion = new SqlConnection(Conexion.CadenaConexion);

                SqlCommand cmdEliminarRegistrado = new SqlCommand("EliminarUsuarioRegistrado", conexion);
                cmdEliminarRegistrado.CommandType = CommandType.StoredProcedure;

                cmdEliminarRegistrado.Parameters.AddWithValue("@cedula", registrado.Cedula);

                SqlParameter retorno = new SqlParameter("@valorRetorno", SqlDbType.Int);
                retorno.Direction = ParameterDirection.ReturnValue;

                cmdEliminarRegistrado.Parameters.Add(retorno);

                conexion.Open();

                int filasAfectadas = cmdEliminarRegistrado.ExecuteNonQuery();

                switch ((int)retorno.Value)
                {
                case 1:
                    throw new ExcepcionPersistencia("No existe un usuario con la cédula " + registrado.Cedula);
                    break;

                case 2:
                    throw new ExcepcionPersistencia("No se pudo eliminar el cliente");
                    break;

                case 3:
                    throw new ExcepcionPersistencia("No se pudo eliminar el usuario");
                    break;

                case 4:
                    throw new ExcepcionPersistencia("No se pudo eliminar las lineas de pedido del usuario.");
                    break;

                case 5:
                    throw new ExcepcionPersistencia("No se pudo eliminar los pedidos pendientes del usuario");
                    break;

                case 6:
                    throw new ExcepcionPersistencia("No se pudo eliminar el usuario");
                    break;
                }

                if (filasAfectadas < 1)
                {
                    throw new ExcepcionPersistencia("Se produjo un error al eliminar el usuario cliente");
                }
            }
            finally
            {
                if (conexion != null)
                {
                    conexion.Close();
                }
            }
        }
        public static void Agregar(UsuarioRegistrado registrado)
        {
            SqlConnection conexion = null;

            try
            {
                conexion = new SqlConnection(Conexion.CadenaConexion);

                SqlCommand cmdAgregarRegistrado = new SqlCommand("AgregarUsuarioRegistrado", conexion);
                cmdAgregarRegistrado.CommandType = CommandType.StoredProcedure;

                cmdAgregarRegistrado.Parameters.AddWithValue("@cedula", registrado.Cedula);
                cmdAgregarRegistrado.Parameters.AddWithValue("@nombreCompleto", registrado.NombreCompleto);
                cmdAgregarRegistrado.Parameters.AddWithValue("@nombreUsuario", registrado.NombreUsuario);
                cmdAgregarRegistrado.Parameters.AddWithValue("@contrasenia", registrado.Contrasenia);
                cmdAgregarRegistrado.Parameters.AddWithValue("@foto", registrado.Imagen);
                cmdAgregarRegistrado.Parameters.AddWithValue("@direccion", registrado.DireccionEnvio);
                cmdAgregarRegistrado.Parameters.AddWithValue("@numeroTarjeta", registrado.NumeroTarjeta);
                cmdAgregarRegistrado.Parameters.AddWithValue("@telefono", registrado.Telefono);
                cmdAgregarRegistrado.Parameters.AddWithValue("@eliminado", registrado.Eliminado);

                SqlParameter retorno = new SqlParameter("@valorRetorno", SqlDbType.Int);
                retorno.Direction = ParameterDirection.ReturnValue;

                cmdAgregarRegistrado.Parameters.Add(retorno);

                conexion.Open();

                int filasAfectadas = cmdAgregarRegistrado.ExecuteNonQuery();

                switch ((int)retorno.Value)
                {
                case 1:
                    throw new ExcepcionPersistencia("Ya existe un usuario con la cédula " + registrado.Cedula);
                    break;

                case 2:
                    throw new ExcepcionPersistencia("El nombre de usuario " + registrado.NombreUsuario + " ya está en uso");
                    break;

                case 3:
                    throw new ExcepcionPersistencia("No se pudo agregar el usuario");
                    break;

                case 4:
                    throw new ExcepcionPersistencia("No se pudo agregar el usuario cliente");
                    break;

                    if (filasAfectadas < 1)
                    {
                        throw new ExcepcionPersistencia("Se produjo un error al agregar el usuario cliente.");
                    }
                }
            }

            finally
            {
                if (conexion != null)
                {
                    conexion.Close();
                }
            }
        }