public bool UpdateLogin(SecUsuario usuario)
        {
            using (var scope = _database.GetTransaction())
            {
                _database.Update(usuario, new string[] { "lastlogin" });

                scope.Complete();
            }

            return(true);
        }
        public bool Insert(SecUsuario usuario)
        {
            using (var scope = _database.GetTransaction())
            {
                _database.Insert("SecUsuario", "id", true, usuario);
                PersistRoles(usuario);

                scope.Complete();
            }

            return(true);
        }
        public bool Update(SecUsuario usuario)
        {
            using (var scope = _database.GetTransaction())
            {
                _database.Update(usuario, new string[] { "idnegocio", "idpais", "activo" });
                _database.Execute("delete from SecRolUsuario where idsecusuario=@0", usuario.Id);
                PersistRoles(usuario);

                scope.Complete();
            }

            return(true);
        }
 private void PersistRoles(SecUsuario usuario)
 {
     if (usuario.Roles != null && usuario.Roles.Count > 0)
     {
         foreach (var rol in usuario.Roles)
         {
             if (!string.IsNullOrEmpty(rol.Codigo) && rol.Id != 0)
             {
                 _database.Execute("insert into SecRolUsuario (idsecusuario, idsecrol) values (@0, @1)", usuario.Id, rol.Id);
             }
             else
             {
                 throw new ApplicationException(string.Format("Usuario {0} con roles invalidos", usuario.Username));
             }
         }
     }
 }
Exemplo n.º 5
0
        public SecRol Map(SecRol rol, SecUsuario usuario)
        {
            // Terminating call.  Since we can return null from this function
            // we need to be ready for PetaPoco to callback later with null
            // parameters
            if (rol == null)
            {
                return(current);
            }

            // Is this the same tag as the current one we're processing
            if (current != null && current.Id == rol.Id)
            {
                // Yes, just add this usuario to the current tag's collection of articles
                if (usuario != null)
                {
                    current.Usuarios.Add(usuario);
                }

                // Return null to indicate we're not done with this tag yet
                return(null);
            }

            // This is a different tag to the current one, or this is the
            // first time through and we don't have an tag yet

            // Save the current tag
            var prev = current;

            // Setup the new current tag
            current = rol;
            if (usuario != null && usuario.Id != int.MinValue)
            {
                current.Usuarios.Add(usuario);
            }

            return(prev);
        }
        public SecUsuario Map(SecUsuario usuario, SecRol rol)
        {
            // Terminating call.  Since we can return null from this function
            // we need to be ready for PetaPoco to callback later with null
            // parameters
            if (usuario == null)
            {
                return(current);
            }

            // Is this the same usuario as the current one we're processing
            if (current != null && current.Id == usuario.Id)
            {
                // Yes, just add this tag to the current usuario's collection of tags
                current.Roles.Add(rol);

                // Return null to indicate we're not done with this usuario yet
                return(null);
            }

            // This is a different author to the current one, or this is the
            // first time through and we don't have an author yet

            // Save the current author
            var prev = current;

            // Setup the new current author
            current = usuario;
            if (rol.Id != 0)
            {
                current.Roles.Add(rol);
            }
            //current.Tags = new List<Tag>();
            //current.posts.Add(p);

            // Return the now populated previous author (or null if first time through)
            return(prev);
        }