This is a nice article that talks about working with SharePoint groups programmatically.
The only problem I had was I had to replace the lines
SPRoleDefinitionBindingCollection roleDefBindings = roleAssignment.RoleDefinitionBindings;
with SPRoleDefinition and added this role definition directly to the SPweb as shown below
SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)group);
def = web.RoleDefinitions["Full Control"];