protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //si llego in id
                int id = Utils.ToInt(Request.QueryString["id"]);
                if (id > 0)
                {
                    BLL.BaseRepository <User> repositorio = new BLL.BaseRepository <User>();
                    var user = repositorio.Get(id);

                    if (user == null)
                    {
                        MostrarMensaje("error", "Registro no encontrado");
                    }
                    else
                    {
                        LlenaCampos(user);
                    }
                }
            }



            /*void MostrarMensaje(TiposMensaje tipo, string mensaje)
             * {
             * ErrorLabel.Text = mensaje;
             *
             * if (tipo == TiposMensaje.Success)
             *  ErrorLabel.CssClass = "alert-success";
             * else
             *  ErrorLabel.CssClass = "alert-danger";
             * }*/
        }
示例#2
0
        protected void BuscarButton_Click(object sender, EventArgs e)
        {
            //Inicializando el filtro en True
            Expression <Func <User, bool> > filtro = x => true;

            BLL.BaseRepository <User> repositorio = new BLL.BaseRepository <User>();
            int id;

            if (!string.IsNullOrEmpty(FiltroTextBox.Text))
            {
                switch (BuscarPorDropDownList.SelectedIndex)
                {
                case 0:    //ID
                    id     = Utils.ToInt(FiltroTextBox.Text);
                    filtro = c => c.Id_User == id;
                    break;

                case 1:    // nombre
                    filtro = c => c.Name.Contains(FiltroTextBox.Text);
                    break;
                }
            }

            DatosGridView.DataSource = repositorio.GetList(filtro);
            DatosGridView.DataBind();
        }
        protected void EliminarButton_Click(object sender, EventArgs e)
        {
            BLL.BaseRepository <User> repositorio = new BLL.BaseRepository <User>();
            int id = Utils.ToInt(IdTextBox.Text);

            var User = repositorio.Get(id);

            if (User == null)
            {
                MostrarMensaje("error", "Registro no encontrado");
            }
            else
            {
                repositorio.Delete(id);
            }
        }
        protected void GuadarButton_Click(object sender, EventArgs e)
        {
            BLL.BaseRepository <User> repositorio = new BLL.BaseRepository <User>();
            User user = new User();
            bool paso = false;

            LlenaClase(user);

            bool esUnico = true;

            if (user.Id_User == 0)
            {
                paso = repositorio.Save(user);
            }
            else
            {
                var ant = new BLL.BaseRepository <User>().Get(user.Id_User);
                esUnico = new BLL.BaseRepository <User>().GetList(x => x.UserName == x.UserName).Count() <= 0 || user.UserName == ant.UserName;
                if (esUnico)
                {
                    user.Password = ant.Password;
                    paso          = repositorio.Modify(user);
                }
                else
                {
                    paso = false;
                }
            }


            if (paso)
            {
                MostrarMensaje("success", "Transaccion Exitosa!");
                Limpiar();
            }
            else
            {
                string mensaje = "No fue posible terminar la transacción";
                if (!esUnico)
                {
                    mensaje += " porque el nombre de usuario esta en uso.";
                }
                MostrarMensaje("error", mensaje);
            }
        }