예제 #1
0
        public ResponseModel ValidarLogin(string usuario, string password)
        {
            var rm = new ResponseModel();

            try
            {
                using (var db = new Model_Sistema())
                {
                    password = HashHelper.MD5(password);
                    var usu = db.Usuario.Where(x => x.usuario1 == usuario)
                              .Where(x => x.clave == password)
                              .SingleOrDefault();

                    if (usu != null)
                    {
                        SessionHelper.AddUserToSession(usu.usuario_id.ToString());
                        rm.SetResponse(true);
                    }
                    else
                    {
                        rm.SetResponse(false, "Usuario o password incorrecto");
                    }
                }
            }
            catch
            {
                throw;
            }

            return(rm);
        }
예제 #2
0
        public ResponseModel GuardarPerfil(Persona persona)
        {
            var rm = new ResponseModel();

            using (var db = new Model_Sistema())
            {
                db.Configuration.ValidateOnSaveEnabled = false;

                var per = db.Entry(this);

                per.State = EntityState.Modified;

                if (persona != null)
                {
                    if (this.persona_id == 0)
                    {
                        per.Property(x => x.persona_id).IsModified = false;
                    }
                    if (this.estado == null)
                    {
                        per.Property(x => x.estado).IsModified = false;
                    }
                    if (this.dni == null)
                    {
                        per.Property(x => x.dni).IsModified = false;
                    }
                    if (this.apellido == null)
                    {
                        per.Property(x => x.apellido).IsModified = false;
                    }
                    if (this.nombre == null)
                    {
                        per.Property(x => x.nombre).IsModified = false;
                    }


                    db.SaveChanges();
                    rm.SetResponse(true);
                }
            }

            return(rm);
        }
예제 #3
0
        public ResponseModel GuardarPerfil(HttpPostedFileBase Foto)
        {
            var rm = new ResponseModel();

            try
            {
                using (var db = new Model_Sistema())
                {
                    db.Configuration.ValidateOnSaveEnabled = false;

                    var usu = db.Entry(this);
                    usu.State = EntityState.Modified;

                    if (Foto != null)
                    {
                        const int size            = 1024 * 1024 * 5;
                        var       filtroextension = new[] { ".jpg", ".jpeg", ".png", ".gif" };
                        var       extensiones     = Path.GetExtension(Foto.FileName);

                        if (filtroextension.Contains(extensiones) && (Foto.ContentLength <= size))
                        {
                            avatar = usuario_id + "_avatar" + extensiones;
                            Foto.SaveAs(HttpContext.Current.Server.MapPath("~/Uploads/" + avatar));
                        }
                        else
                        {
                            usu.Property(x => x.avatar).IsModified = false;
                        }

                        if (this.usuario_id == 0)
                        {
                            usu.Property(x => x.usuario_id).IsModified = false;
                        }
                        if (this.persona_id == 0)
                        {
                            usu.Property(x => x.persona_id).IsModified = false;
                        }
                        if (this.usuario1 == null)
                        {
                            usu.Property(x => x.usuario1).IsModified = false;
                        }
                        if (this.nivel == null)
                        {
                            usu.Property(x => x.nivel).IsModified = false;
                        }
                        if (this.estado == null)
                        {
                            usu.Property(x => x.estado).IsModified = false;
                        }
                        if (this.clave == null)
                        {
                            usu.Property(x => x.clave).IsModified = false;
                        }

                        db.SaveChanges();
                        rm.SetResponse(true);
                    }
                }
            }
            catch (DbEntityValidationException)
            {
                throw;
            }

            return(rm);
        }