AddingNewUserWithTransaction.AddingNewUserWithTransactionUI.AddUserToGroup C# (CSharp) Method

AddUserToGroup() static private method

static private AddUserToGroup ( string userName, string groupName ) : bool
userName string
groupName string
return bool
        static bool AddUserToGroup(string userName, string groupName)
        {
            using (UsersGroupsEntities context = new UsersGroupsEntities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    if (!context.Groups.Where(g => g.Name == groupName).Any())
                    {
                        context.Groups.Add(new Group() { Name = groupName });
                        context.SaveChanges();
                    }

                    Group groupToAddIn = context.Groups.Where(g => g.Name == groupName).First();
                    if (groupToAddIn.Users.Where(u => u.Name == userName).Any())
                    {
                        scope.Dispose();
                        return false;
                    }
                    else
                    {
                        User newUser = new User() { Name = userName };
                        groupToAddIn.Users.Add(newUser);
                        context.SaveChanges();
                        scope.Complete();
                        return true;
                    }
                }
            }
        }
    }
AddingNewUserWithTransactionUI