コード例 #1
0
        public ResponseModel Guardar()
        {
            var rm = new ResponseModel();

            try
            {
                using (var ctx = new PortafolioModel())
                {
                    var Habilidad = ctx.Entry(this);
                    if (this.id > 0)
                    {
                        Habilidad.State = EntityState.Modified;
                    }
                    else
                    {
                        Habilidad.State = EntityState.Added;
                    }
                    ctx.SaveChanges();
                    rm.SetResponse(true);
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(rm);
        }
コード例 #2
0
        public ResponseModel Acceder(string Email, string Password)
        {
            ResponseModel rm = new ResponseModel();

            try
            {
                using (var ctx = new PortafolioModel())
                {
                    Password = HashHelper.MD5(Password);
                    var usuario = ctx.Usuarios.Where(x => x.Email == Email)
                                  .Where(x => x.Password == Password)
                                  .SingleOrDefault();

                    if (usuario != null)
                    {
                        SessionHelper.AddUserToSession(usuario.id.ToString());
                        rm.SetResponse(true);
                    }
                    else
                    {
                        rm.SetResponse(false, "Acceso denegado");
                    }
                }

                return(rm);
            }
            catch (Exception ex)
            {
                rm.SetResponse(false, ex.Message);
            }
            return(rm);
        }
コード例 #3
0
        public Habilidad Obtener(int id)
        {
            var habilidad = new Habilidad();

            try
            {
                using (var ctx = new PortafolioModel())
                {
                    habilidad = ctx.Habilidads.Where(x => x.id == id).FirstOrDefault();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(habilidad);
        }
コード例 #4
0
        public Experiencia Obtener(int id)
        {
            var experiencia = new Experiencia();

            try
            {
                using (var ctx = new PortafolioModel())
                {
                    experiencia = ctx.Experiencias.Where(x => x.id == id).FirstOrDefault();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(experiencia);
        }
コード例 #5
0
        public List <Habilidad> ObtenerLista(int id_usuario)
        {
            var Habilidad = new List <Habilidad>();

            try
            {
                using (var ctx = new PortafolioModel())
                {
                    Habilidad = ctx.Habilidads.Where(x => x.Usuario_id == id_usuario)
                                .ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(Habilidad);
        }
コード例 #6
0
        public List <TablaDato> Listar(string relacion)
        {
            var datos = new List <TablaDato>();

            try
            {
                using (var ctx = new PortafolioModel())
                {
                    datos = ctx.TablaDatoes.Where(x => x.Relacion == relacion)
                            .OrderBy(x => x.Orden)
                            .ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(datos);
        }
コード例 #7
0
        public List <Experiencia> ObtenerLista(int tipo, int id_usuario)
        {
            var experiencia = new List <Experiencia>();

            try
            {
                using (var ctx = new PortafolioModel())
                {
                    experiencia = ctx.Experiencias.Where(x => x.Tipo == tipo)
                                  .Where(x => x.Usuario_id == id_usuario)
                                  .ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(experiencia);
        }
コード例 #8
0
        public Usuario Obtener(int idUsuario)
        {
            Usuario usuario = new Usuario();

            try
            {
                using (var ctx = new PortafolioModel())
                {
                    usuario = ctx.Usuarios.Where(x => x.id == idUsuario)
                              .FirstOrDefault();
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(usuario);
        }
コード例 #9
0
        public ResponseModel Guardar(HttpPostedFileBase foto)
        {
            var rm = new ResponseModel();

            try
            {
                using (var ctx = new PortafolioModel())
                {
                    ctx.Configuration.ValidateOnSaveEnabled = false;
                    var eUsuario = ctx.Entry(this);
                    eUsuario.State = EntityState.Modified;

                    if (foto != null)
                    {
                        string archivo = DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetExtension(foto.FileName);
                        foto.SaveAs(HttpContext.Current.Server.MapPath("~/uploads/" + archivo));
                        this.Foto = archivo;
                    }
                    else
                    {
                        eUsuario.Property(x => x.Foto).IsModified = false;
                    }

                    if (this.Password == null)
                    {
                        eUsuario.Property(x => x.Password).IsModified = false;
                    }

                    ctx.SaveChanges();
                    rm.SetResponse(true);
                }
            }
            catch (DbEntityValidationException e)
            {
            }
            catch (Exception)
            {
                throw;
            }

            return(rm);
        }
コード例 #10
0
        public ResponseModel Eliminar(int id)
        {
            var rm = new ResponseModel();

            try
            {
                using (var ctx = new PortafolioModel())
                {
                    var Habilidad = ctx.Habilidads.Where(x => x.id == id).FirstOrDefault();
                    var entry     = ctx.Entry(Habilidad);
                    entry.State = EntityState.Deleted;
                    ctx.SaveChanges();
                    rm.SetResponse(true);
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(rm);
        }